Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^5: Short form (ternary) if else

by Riales (Hermit)
on Feb 08, 2012 at 22:22 UTC ( #952606=note: print w/ replies, xml ) Need Help??


in reply to Re^4: Short form (ternary) if else
in thread Short form (ternary) if else

Wrong, it can indeed execute code:

sub foo1 { print "Hello, World!\n"; } sub foo2 { print "Goodbye, World!\n"; } 1 ? foo1() : foo2(); 0 ? foo1() : foo2();
This prints:
Hello, World! Goodbye, World!
I think what you're confused about is still scope; like the if/else block in the original post, if you declare my $vxdg inside the ternary operator, it will fall out of scope before you try to access it again.


Comment on Re^5: Short form (ternary) if else
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://952606]
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: (3)
As of 2015-07-05 09:29 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 (61 votes), past polls