Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^4: Shortcut operator for $a->{'b'}=$b if $b;

by leriksen (Curate)
on Sep 21, 2005 at 03:24 UTC ( [id://493648]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Shortcut operator for $a->{'b'}=$b if $b;
in thread Shortcut operator for $a->{'b'}=$b if $b;

Maybe someone can suggest how to define a '?=' operator

$a->{'b'} ?= $b;

assigns $b to $a->{'b'} if $b is defined, does not autovivify $a->{'b'} if $b not defined

is that possible? - I'm thinking of use overload but I dimly recall that there is a finite set of operators you can overload and ?= isnt one of them.

...reality must take precedence over public relations, for nature cannot be fooled. - R P Feynmann

Replies are listed 'Best First'.
Re^5: Shortcut operator for $a->{'b'}=$b if $b;
by ikegami (Patriarch) on Sep 21, 2005 at 05:28 UTC

    overload doesn't define operators; it redefines them. ?= would have to be added to perl by patch.

    There is an alternative to a new or overloaded operator. One could use a tied hash. The only difference would be in the setter.

    By the way, my function does not autovivify. At least, not in 5.6.x or 5.8.x.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (9)
As of 2024-04-19 08:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found