Hi Bob.

"Bob Showalter" <[EMAIL PROTECTED]> wrote in message
2E4528861499D41199D200A0C9B15BC001D7E652@FRISTX">news:2E4528861499D41199D200A0C9B15BC001D7E652@FRISTX...
> Rob Dixon wrote:
> > ...
> > You're right, I'm wrong, and I hereby resign.
> >
> >     perl -p -i -e "redo if /^\s*$/" file.ext
> >
> > is completely wrong, as the redo doesn't pull in the next line from
> > the input. It simply retests the same blank line indefinitely. The
> > neater
> >
> >     perl -p -i -e "s/^\s*$//" file.ext
> >
> > is the correct way.
>
> Why not just
>
>    perl -pi -e 'next if /^$/';           # skip empty lines
>
> or,
>
>    perl -pi -e 'next unless /\S/';       # skip lines containing only
> whitespace

Because using 'next' will process the continue block of the loop before
going to the top and fetching the next input line. Since the -p qualifier
introduces something like:

    while (<>)
    {
        # Your code here
    }
    continue
    {
        print;
    }

around your code, the line will be printed regardless of the result of the
test. The neatest way is to replace each blank line with the null string so
that the print statement, when executed, produces no output.

Cheers,

Rob




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to