in reply to Re^2: Extracting elements from array
in thread Extracting elements from array
The point to map is that you can run the elements of the list through any code you like in the map block.
map assigns the result of the last evaluated statement in the block, you don't always have to can't say return $foo;, but can just say $foo, as shown in all these examples. I tend to eschew many of Perl's shortcuts (like omitting a return statement from a block) because I prefer readability, but when it's a single statement, as is often the case with map, it's nice to be able to skip it.
But if it's clearer to you to write:
then by all means do that. edit: no, don't do thatmy @hash_names = map{ return {name => $_}; } @all_names;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Extracting elements from array
by choroba (Cardinal) on Jan 15, 2016 at 14:00 UTC |