in reply to Re^3: Useless use of string in return statement
in thread Useless use of string in return statement

Are you suggesting postfix if should never be used?

My rule of thumb is Statement Modifiers should only be used on things that really only are a single statement, not multiple things stuck together with the Comma Operator or a do BLOCK. (Update: To clarify: IMHO and TIMTOWTDI.)

  • Comment on Re^4: Useless use of string in return statement

Replies are listed 'Best First'.
Re^5: Useless use of string in return statement
by jdporter (Paladin) on Apr 13, 2021 at 16:15 UTC

    Someone, I believe it was Larry, said that the choice should be made such that the "most important part" of the statement comes first/leftmost. So in the case of error handling - such as the failure of open - using the modifier 'if' is appropriate.

      But what *is* the most important part with errors?

      die "I hate you" if $string =~ m/error/i;

      or

      $string =~ m/error/i and die "I hate you";

      As with most, it is a matter of taste and brain. *My* brain 100% prefers the second over the first. Note that I am not of native English tongue. That might matter.

      My rule of thumb is to forbid all postfix if/unless except when the expression is a simple $debug / $verbose >= $n.


      Enjoy, Have FUN! H.Merijn

        I agree... and now I realize that I mis-wrote when I said "modifier if". I actually meant 'and', as you showed.