Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

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

by Roy Johnson (Monsignor)
on Sep 20, 2005 at 16:46 UTC ( #493514=note: print w/ replies, xml ) Need Help??


in reply to Shortcut operator for $a->{'b'}=$b if $b;

Something like

{ $a->{'b'} = do {$b or last} }
might abort the assignment if $b is not true. I can't test it at the moment. Another idea that occurs to me is
($a->{'b'} = $b) or delete $a->{'b'};
which expresses pretty directly what you said in your last sentence.

Caution: Contents may have been coded under pressure.


Comment on Re: Shortcut operator for $a->{'b'}=$b if $b;
Select or Download Code
Re^2: Shortcut operator for $a->{'b'}=$b if $b;
by ikegami (Pope) on Sep 20, 2005 at 16:52 UTC
    Tested. last does the trick.
Re^2: Shortcut operator for $a->{'b'}=$b if $b;
by japhy (Canon) on Sep 20, 2005 at 16:54 UTC
Re^2: Shortcut operator for $a->{'b'}=$b if $b;
by Aristotle (Chancellor) on Sep 20, 2005 at 20:35 UTC

    It doesn’t “abort” the assignment – the logical OR is evaluated first, then possibly the last, and if that is evaluated, it prevents the assignment from evaluating at all. And thus it works.

    Makeshifts last the longest.

      And thereby logical false values do not get assigned, which is not as per the specs.

      CountZero

      "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

        You should re-read the OP's post. It says "The point is to have no key 'b' exist if $b is false."

        Caution: Contents may have been coded under pressure.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (9)
As of 2014-08-20 15:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (116 votes), past polls