in reply to Perldoc's explanation of the difference between '&&' and 'and' has me confused

My stylistic advice on this topic: Re: Thoughts on using and, or, and not over && || !?

  • Comment on Re: Perldoc's explanation of the difference between '&&' and 'and' has me confused

Replies are listed 'Best First'.
Re^2: Perldoc's explanation of the difference between '&&' and 'and' has me confused
by Tux (Canon) on Jul 05, 2021 at 12:22 UTC

    I agree in principle, but I tend to also use and and or in very complex expressions to be able to use less parens:

    if (($foo && ($bar || $zebra) && ($fox & $mask) && $option_x) || ($zul +y & $mask2 || $lion)) {

    =>

    if ($foo && ($bar || $zebra) && ($fox & $mask) && $option_x or $zuly & + $mask2 || $lion) {

    most often with line breaks. The "or" and "and" will be bold in my editors syntax highlighting making it even more clear what the logical groups are. YMMV.


    Enjoy, Have FUN! H.Merijn
      Honestly, I find this still pretty unreadable.

      Probably because it's a contrived example?

      If this actually was realworld code I'd add many line-breaks and comments for each line.

      Or even better break it down into speaking variables for sub-terms.

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

        Or break it down into multiple statements.

        Seeking work! You can reach me at ikegami@adaelis.com