in reply to Re: searching the strings
in thread searching the strings

/^>>/ and do { print "error message\n"; next };

I like to use short-circuiting logical operators for flow control, and to omit unnecessary parentheses, but I'd avoid using do like that, if possible. How 'bout the following instead?

print("error message\n"), next if /^>>/; # or (print "error message\n"), next if /^>>/;

Replies are listed 'Best First'.
Re^3: searching the strings
by Hue-Bond (Priest) on May 10, 2006 at 13:39 UTC

    I've seen it in the Camel ("2.6. Statements and declarations", "Bare blocks and case structures"), so I thought it would be ok. Indeed I think it's ok since it is listed only as one of several alternatives (another one of which is the one you posted).

    --
    David Serrano

      The alternative the grandparent suggested
      print("error message\n"), next if /^>>/;
      could easily be confused for
      print("error message\n"); next if /^>>/;
      I don't think it's a very good idea.

      At least what you used is well established. It is quite ugly, though. I usually fall back to if/elsif. if/elsif even produces shorter lines:

      foreach (@w) { print "working with $_... "; if (/^>>/ ) { print "error message\n" } elsif (/^\s*([<>])\s*(\S+)/) { print "separated '$1' from '$2'\n" } elsif (/^\s*\|/ ) { print "pipefront\n" } elsif (/\|\s*$/ ) { print "pipeend\n" } else { print "\n" } }

        ++ but I have never been confused, nor have I seen anyone confusing ; for , in this case.

        PS: it was me, not GrandFather...