Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Re: (my?) problem with re-blessed references(?)

by demerphq (Chancellor)
on Dec 13, 2002 at 13:30 UTC ( [id://219573]=note: print w/replies, xml ) Need Help??


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?

    :-) :-)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://219573]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-20 16:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found