On Thu, Jun 22, 2000 at 08:03:14PM +0100, Fergal Daly wrote:
> perl -ne '<>;print' filename
>> perl -ne 'print;<>' filename
>> Hmm... just tested those last 2 and they both print only the odds, what's
> going on there?
In both of the above examples, the code which is executed prints $_ (print)
and reads one more line from the input source (<>) - it doesn't matter which
order they're done in - the net result is to print the odd line, and slurp
in the even. You may be assuming that <> in scalar context is equivalent to
$_ = <> but t'ain't so. To print the even lines, you could use
perl -ne 'print $a = <>' filename
> I don't think this'll be beat
>> perl -pe '<>' filename
No, I don't suppose it will :-) and it certainly won't be beat for obscurity.
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!