En op 11 april 2002 sprak Yanick:
> $ perl -v
> This is perl, v5.6.1 built for i386-linux
> $ perl -le'%a = qw/ a b c d/; s/./uc$&/e for %a; print %a'
> aBcD
> 
>       And this one really takes the cake. Keys are modified,
> but not values... But wait! There is more!

No, values are modified, keys are not. But that's not so strange: hash
values are scalars; hash keys are strings:

$ perl -le'$a{[1,2,3]} = [4,5,6]; print "$_: @$_" for %a'
ARRAY(0x140001ad0): 
ARRAY(0x1400019e0): 4 5 6

s/// and other operators only work on scalar values, so a key has to be
copied into a scalar value to be assigned to $_. A hash value is already
a value, and can be aliased to $_.

Does that make sense?

Eugene

-- 
Don't play too much golf. Two rounds a day are plenty. -- Harry Vardon

Reply via email to