in reply to Re^3: in search of a more elegant if then else
in thread in search of a more elegant if then else
This gets a little prettier in Perl 6, since it parses the inside of parens as a statement:
Also, you can usually omit the curlies on a do, if the insides can terminate the whole statement...which it can't if there's a modifier, as above, so we'll invert it:say (if $_ { 'fred' } else { 'bill' }) for 0..1;
Of course, there's also the ternary operator, spelled ?? !!, if you want it...for 0..1 { say do if $_ { 'fred' } else { 'bill' } }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^5: in search of a more elegant if then else
by BrowserUk (Patriarch) on Feb 20, 2010 at 17:25 UTC | |
by TimToady (Parson) on Feb 20, 2010 at 18:13 UTC | |
by BrowserUk (Patriarch) on Feb 21, 2010 at 00:22 UTC | |
by TimToady (Parson) on Feb 21, 2010 at 03:13 UTC |
In Section
Seekers of Perl Wisdom