SPUG:Best One-Liners and Scripts for UNIX
Michael R. Wolf
MichaelRunningWolf at att.net
Tue May 6 21:12:21 CDT 2003
Tim Maher <tim at consultix-inc.com> writes:
[...]
> * 5 Perl One-liners All Unix/Linux Users Should Know
> * 3 Perl Scripts UNIX/Linux Users Shouldn't Live Without
> * How Perl's Looping Facilities Compare to the Shell's
Better late than never.
Here's one of my favorite idioms
while(<>) {
next if /^\s*#/; # skip shell-like comment lines
next if /^\s*$/; # skip blank lines
# process data here
}
I often use it as
while(<DATA>) {
...
}
to read in some "magic" data from the DATA filehandle.
This has come in very handy in many cases. I love to add whitespace to
my data, breaking it into readable paragraphs. And I like to *disable*
rather than *remove* the data -- it's so much easier to *enable* it
than to *create* it from scratch.
--
Michael R. Wolf
All mammals learn by playing!
MichaelRunningWolf at att.net
More information about the spug-list
mailing list