"Bob Showalter" <[EMAIL PROTECTED]> wrote in message
2E4528861499D41199D200A0C9B15BC001D7E653@FRISTX">news:2E4528861499D41199D200A0C9B15BC001D7E653@FRISTX...
> Rob Dixon wrote:
> > Hi Bob.
> >
> > "Bob Showalter" <[EMAIL PROTECTED]> wrote in message
> > 2E4528861499D41199D200A0C9B15BC001D7E652@FRISTX">news:2E4528861499D41199D200A0C9B15BC001D7E652@FRISTX...
> > >
> > > 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.
>
> Oops! Of course.
>
> In that case, how about inverting the approach:
>
> perl -ni -e 'print unless /^$/';
>
I thought of that but, checking with the Camel, the actual continue block
looks like:
continue
{
print or die "-p destination: $!\n";
}
which the -n qualifier doesn't do, is too good to miss for free, and is too
clumsy to code explicitly in the command line.
I must admit I don't like emptying the string just because we can't avoid it
being printed, but it's not a real problem.
Cheers,
Rob
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]