Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

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

by merlyn (Sage)
on Sep 20, 2005 at 16:33 UTC ( #493507=note: print w/ replies, xml ) Need Help??


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

Ugly, but short:

$_ and $a->{b} = $_ for $b;

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.


Comment on Re: Shortcut operator for $a->{'b'}=$b if $b;
Download Code
Re^2: Shortcut operator for $a->{'b'}=$b if $b;
by chester (Hermit) on Sep 20, 2005 at 16:43 UTC
    What's the for doing, there? Doesn't this work?

    $b and $a->{'b'} = $b

    edit: Doesn't solve the problem fully.

        Ah, I see. My mistake.

      foreach loops sets $_ to refer to the current value in the list which is being iterated. In this case, the list consists solely of $b.

      Your expression is equivalent, but it's not an acceptable answer since the question was about removing the need for using $b twice.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (14)
As of 2014-10-23 15:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (125 votes), past polls