Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: Perl: last evaluated value as a returned value for a subroutine. See inside

by LanX (Bishop)
on Feb 21, 2013 at 17:00 UTC ( #1019983=note: print w/replies, xml ) Need Help??

in reply to Perl: last evaluated value as a returned value for a subroutine. See inside

your output must be wrong, only the first call should print "some string".

EDIT: now I get it, the sub returns the evaluation from the unless-condition in the first line.

... WTF ...

You like obfuscation, don't you?

> are there any conditions when Perl would NOT print "some string" in last two lines of code

sure if you set $R to anything false ( EDIT:... it will start from new, otherwise it will print the new value.)

if you wanna avoid that anyone ever unintentionally changes $R, then put the whole closure construct into braces and $R is out of scope for any other code.

{ my $R; sub mySub { unless ($R) { print "CONDITION WORKS\n"; $R = 'some string'; } } }

Cheers Rolf

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1019983]
[Discipulus]: i the moment likely no
[karlgoethebier]: i wonder now it will be with my glasses.
[Discipulus]: Milan Perl Mongers seems frozen at 2009
[Discipulus]: karl you dont shoot with eyes, you shoot with the soul
[jkva]: Reminds me of Guardians of the Galaxy
[erix]: OT++: /me came across an osprey (=visarend (=Fischadler)) just now
[erix]: (osprey are pretty rare in NL)

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (9)
As of 2017-10-20 10:07 GMT
Find Nodes?
    Voting Booth?
    My fridge is mostly full of:

    Results (260 votes). Check out past polls.