in reply to Write code diferently
You can replace map with a for loop and an assignment. There is an example of allocation to a hash with both map and a loop to be found in the map documentation http://perldoc.perl.org/functions/map.html
From Perldoc
Map always returns a list, which can be assigned to a hash such that the elements become key/value pairs. See perldata for more details.
%hash = map { get_a_key_for($_) => $_ } @array;
is just a funny way to write
%hash = (); foreach (@array) { $hash{get_a_key_for($_)} = $_; }
Cheers,
R.
Pereant, qui ante nos nostra dixerunt!
|
---|
In Section
Seekers of Perl Wisdom