On Sep 22, John W. Krahn said:

The if statement modifier is just another way to write a logical and statement:

$ perl -MO=Deparse -e' display_nothing() if $match_type eq q/none/ '
display_nothing() if $match_type eq 'none';
-e syntax OK
$ perl -MO=Deparse -e' $match_type eq q/none/ and display_nothing() '
display_nothing() if $match_type eq 'none';
-e syntax OK
$ perl -MO=Deparse -e' $match_type eq q/none/ && display_nothing() '
display_nothing() if $match_type eq 'none';
-e syntax OK

An important difference, though, is that the if statement modifier takes an expression and produces a statement, so you can't store its return value somewhere. That is,

  $result = (do_this() if that());

is a syntax error.  Not so in the case of '&&' and 'and':

  $result = (that() and do_this());
  $result = (that() && do_this());

However, you can turn any statement into an expression by using do { } around the statement:

  $result = do { do_this() if that(); };

--
Jeff "japhy" Pinyan        %  How can we ever be the sold short or
RPI Acacia Brother #734    %  the cheated, we who for every service
http://www.perlmonks.org/  %  have long ago been overpaid?
http://princeton.pm.org/   %    -- Meister Eckhart

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to