Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Ternary Operator with Subroutine

by biohisham (Priest)
on Aug 11, 2011 at 23:08 UTC ( #919963=note: print w/ replies, xml ) Need Help??


in reply to Ternary Operator with Subroutine

When you assign to a reference a value (in this case an anonymous sub), dereference that reference to access its value:

hisham@bioslayer:~$ perl - my $subref = sub{print 'a',"\n";}; (my $test)?print 'c' : $subref->(); #dereference with infix arrow oper +ator __END__ a hisham@bioslayer:~$ perl - my $subref = sub{print 'a',"\n"}; (my $test)?print 'c' : &{$subref}; #dereference with &{} __END__ a
check %perldoc perlsub



David R. Gergen said "We know that second terms have historically been marred by hubris and by scandal." and I am a two y.o. monk today :D, June,12th, 2011...


Comment on Re: Ternary Operator with Subroutine
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://919963]
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: (7)
As of 2015-07-30 00:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (269 votes), past polls