Think about Loose Coupling | |
PerlMonks |
Re: "map" sometimes uses only the last mapped valueby turo (Friar) |
on Apr 18, 2006 at 13:57 UTC ( [id://544061]=note: print w/replies, xml ) | Need Help?? |
Seems to be a problem with references ... The map operator receives all the elements of the array (x, y, z) and passes all of them correctly to the function f2: Extrange, is like the function f2, only has been collecting the ref of the $d variable, and when print is going to print the array, it prints the value of the same reference; that is the last 'z' (what's about the scopes!!! arrg) I have solved the problem using a intermediate variable:
cheers
perl -Te 'print map { chr((ord)-((10,20,2,7)[$i++])) } split //,"turo"'
In Section
Seekers of Perl Wisdom
|
|