in reply to map split vs array split
my @words = map { split } <FH>;
Four things are happening here...
Why is this evaluating split of array to scalar?
Because it's within a string. Perl evaluates print "\@lines1 is @lines1" as print '@lines1 is ' . @lines1. Concatenation forces scalar context on its operands. scalar @lines1 returns the number of element in the array.
See my reply below for the real answer to this.
print "@lines1" is treated magically: each element of @lines1 is printed, separated by a space.
update: ysth pointed out that what I'd written was wrong. Sorry about that.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: map split vs array split
by convenientstore (Pilgrim) on Jul 30, 2007 at 23:18 UTC | |
by FunkyMonk (Chancellor) on Jul 30, 2007 at 23:54 UTC | |
by radiantmatrix (Parson) on Jul 31, 2007 at 15:18 UTC |