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

ok I think I get it. It returns a value if true, else return value if false. It does not execute code if true or code if false. Is that a correct statement?

Replies are listed 'Best First'.
Re^5: Short form (ternary) if else
by Riales (Hermit) on Feb 08, 2012 at 22:22 UTC
    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.