... This, however, doesn't parallel Perl's documentation. Am I doing something stupid? Is Perl's documentation wrong? Are we both wrong?You're wrong because you're taking an analogy past its limits, ignoring documentation in the interim.
Evaluates the BLOCK or EXPR for each element of LIST (locally setting $_ to each element) and returns the list value composed of the results of each such evaluation...The assignment operator (which is discussed through out the perl documentation) is waiting for map (a list operator) to return a list, before it can proceed with the assignment. To getis just a funny way to write%hash = map { getkey($_) => $_ } @array;%hash = (); foreach $_ (@array) { $hash{getkey($_)} = $_; }
to work as you intended , you need to change it tomy %res = map { $_ => do { my $re; $re .= $translations{$_} for split //; $re; } if !$res{$_}; } @words;
update: or evenmy %res; my @res = map { $_ => do { my $re; $re .= $translations{$_} for split //; $re; } if !$res{$_}; } @words; %res = @res;
my %res; %res = @_ =map { $_ => do { my $re; $re .= $translations{$_} for split //; $re; } if !$res{$_}; } @words;
In reply to beware of funny ways
by PodMaster
in thread Map: Thou Has't Confounded Me For The Last Time! (Referring To The Array You Are Assigning To In Map)
by Revelation
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |