Greetings,
Here is how I understand it.
in your code
my %res = map {
$_ => do {
my $re;
$re .= $translations{$_} for split //;
$re;
} if !$res{$_};
} @words;
you are refering to the list being created, in this case the
%res hash, from within the block doing the assignment, the
map {$_ => do {#code} if !$res{$_};}@words; line. If you take out the
if !$res{$_}; part your resulting
%res hash will have the value of the last of any possible identical values in the
@words array. My gut feeling is that its more the
!$res{$_} part than it is the use of the
%res hash on both sides... but then there is your second example of
my @b = (7,5,5,6);
my @a;
@a = map { $_ > 5 ? $_ : $a[0] } @b;
Which again makes me think it's the use of
%res on both sides of the
= sign. So a basic rule of thumb to use might be that map only works on the contents of @b and never questions @a, only gives (given your example above).
...that made more sense when I started.
Anyone else with a more concise explanation?
-InjunJoel
Update!
Perhaps its the
getkey() that is making it unclear? Have a look at
perldoc question (how to get info on getkey). The
getkey() call was tripping me up in the map documentation when I read it. So assuming that
getkey() is only working on
$_ from
@array and not anything related to
%hash(for it may only giveth) it all makes sense...
"I do not feel obliged to believe that the same God who endowed us with sense, reason and intellect has intended us to forego their use." -Galileo