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.
|
|---|