in reply to Nested OR as a control structure

Did you try something like this...

#!/usr/local/bin/perl use strict; use warnings; my $p = 9; if ( $p ) { sub { printf "$p < 3 ? %s\n" , $p < 3 ? 'yes' : 'no'; return 0; }->() or sub { printf "$p > 3 ? %s\n" , $p > 3 ? 'yes' : 'no'; return 0; }->() or print "I forgot my Math: $p <!> 3!\n" ; }

In other words, if your subs return appropriate truth values, then your posted example should work. Mind you can bundle your subs w/ exit() in anonymous sub references similar to as shown above.

Replies are listed 'Best First'.
Re^2: Nested OR as a control structure
by andyf (Pilgrim) on Jun 02, 2004 at 23:32 UTC
    Ah this is interesting, thanks Parv. Im playing with your anonymous sub refs type thing now. Im returning undefs from failed subs. Encouraging that you also think it should work.
    I wandered into writing it quite naturally, it seemed intuitively right.
    Thanks to the other posters for your thoughts too. I was specifically refering to the syntactic usage of OR even if the question sounded vague. Maybe it is more subtle than it seems, the expression (which I call a block) must behave as the return value of the sub. Damn my C legacy.