in reply to map split vs array split
Seems to me like you want to get rid of the map. You can replace map with another loop.
@array = map { EXPR } LIST;
is functionally equivalent to
@array = (); foreach (LIST) { push @array, EXPR; }
So
open (FH, "foo.txt"); my @words = map { split } <FH>; close FH; print "@words\n";
can be written as
open (FH, "foo.txt"); my @words; foreach (<FH>) { push @words, split; } close FH; print "@words\n";
Since <FILE> can be used as an interator, the following is more memory-efficient:
open (FH, "foo.txt"); my @words; while (<FH>) { push @words, split; } close FH; print "@words\n";
|
|---|