On Tue, Apr 24, 2012 at 1:18 PM, Jesse Luehrs <doy@tozt.net> wrote:
> I have on occasion wished for a more functional programming-style if
> statement:
>
> my $foo = if ($foo->bar) { $bar } else { $baz };
>
> It is a lot more readable than ?: when the expressions get more
> complicated.
C<do> is very handy and will let you do that:
$ perl -le 'my $X = do { if ( 0 ) { 27 } else { 33 }};print $X'
33
$ perl -le 'my $X = do { if ( 1 ) { 27 } else { 33 }};print $X'
27
--
In this document, the key words "MUST", "MUST NOT", "REQUIRED", "SHALL",
"SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and
"OPTIONAL" are to be interpreted using situational ethics.
Thread Previous
|
Thread Next