Yanick ([EMAIL PROTECTED]) wrote:
> On Thu, Apr 11, 2002 at 09:04:22AM -0400, Karger, Amir wrote:
> > I get the same result as you (aBcD) when I run 5.6.1 on
> > solaris. So it looks like the aliasing mechanism switched from
> > 5.004 to 5.6.1.
>
> I get the same behavior:
>
> $ 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!
>
> $ perl -le'%a = qw/ a b c d/; s/./uc$&/e for values %a; print %a'
> aBcD
> $ perl -le'%a = qw/ a b c d/; s/./uc$&/e for keys %a; print %a'
> abcd
>
> So if you specify the values, you can modify them. But if you
> specify the keys, you can't.
These are two sides of the same coin, and not really very surprising,
when you think about how modifying a key potentially means moving it
to a new hash bucket.
If it was possible to modify keys, there may well have been a nice
solution to TPR(0,2), which during the hash-building stage dynamically
changed the keys so that they were always of the form
join $;, 1 x $number_of_words_in_set, sort /./g
Then you could just do a
print@h{sort%h}