Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Howto convert lines in stringified text into element of an array

by ikegami (Patriarch)
on Sep 04, 2007 at 03:33 UTC ( [id://636822]=note: print w/replies, xml ) Need Help??


in reply to Howto convert lines in stringified text into element of an array

Assuming you want the same result as chomp( my @array = <FILE> );,

chomp( my @array = $file =~ /\G(.*\n|.+)/g );

or

my @array = $file =~ /\G(?=.)([^\n]*)\n?/sg;

or

my @array = $file =~ /\G(.*)(?:\n|(?<=.))/g;

or (This one allows you to easily use PerlIO layers)

open my $fh, '<', \$file; chomp( my @array = <$fh> );

If you want a reference to that array, use \:

my $array = \@array;

Update: Added variants.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://636822]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2026-02-16 09:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.