in reply to searching the strings

Let's see if I understood everything:

foreach (@w) { print "working with $_... "; /^>>/ and do { print "error message\n"; next }; /^\s*([<>])\s*(\S+)/ and do { print "separated '$1' from '$2'\n"; ne +xt }; /^\s*\|/ and do { print "pipefront\n"; next }; /\|\s*$/ and do { print "pipeend\n"; next }; print "\n"; } __END__ working with >test.txt... separated '>' from 'test.txt' working with <test.txt... separated '<' from 'test.txt' working with >>test.txt... error message working with | test... pipefront working with test |... pipeend

This probably needs more refinement but I think I'll leave that to you ;).

Update: Code beautification.

--
David Serrano

Replies are listed 'Best First'.
Re^2: searching the strings
by blazar (Canon) on May 10, 2006 at 13:21 UTC
    /^>>/ 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 /^>>/;

      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" } }