in reply to Re: (my?) problem with re-blessed references(?)
in thread (my?) problem with re-blessed references(?)

$foo{shift} is the same as $foo{'shift'} - you want $foo{(shift)}. This is what's causing your overwriting problem - everything is indexed under $whatever{'shift'}.

Just wanted to say that the standard way of doing this is not to parethesize the shift, but to put a + in front of it. This is perls way of ensuring that whatever follows the plus is construed as code and not something else. Note that this is NOT the same as 0+shift, which coerces numeric context.

This is IME particularly useful with print and with hash keys.

print +($.>10) ? "Skipped." : "Ok"; $foo{+shift}=10;

--- demerphq
my friends call me, usually because I'm late....

Replies are listed 'Best First'.
Re^3: (my?) problem with re-blessed references(?)
by Aristotle (Chancellor) on Dec 15, 2002 at 02:01 UTC
    It's also nice for constructing hashes with map: my %foo = map +( $_ => bar($_) ), @baz; which otherwise won't parse correctly.

    Makeshifts last the longest.

Re^3: (my?) problem with re-blessed references(?)
by adrianh (Chancellor) on Dec 13, 2002 at 13:51 UTC
    Just wanted to say that the standard way of doing this...

    Perl has standards?

    :-) :-)