in reply to Re^4: hash array
in thread hash array
map is a looping function to apply an expression or a block to every item in a list (each item in turn assigned to $_), and collect/return the list of results. It's like:
where $CODE is the expression (delimited by a comma) or block (no delimiter) in the first argument.my @results; foreach(@_) { push @results, &$CODE(); } return @results;
example:
which is identical in result to@output = map $_*2, 1 .. 10;
and which return the even numbers from 2 to 20; the double of all numbers between 1 and 10.@output = map { $_*2 } 1 .. 10;
|
---|
In Section
Seekers of Perl Wisdom