[CentOS] grep

Stephen Harris lists at spuddy.org
Wed Aug 29 03:30:07 UTC 2007


On Tue, Aug 28, 2007 at 05:04:33PM -0500, Les Mikesell wrote:

> It's easy to hate perl that other people have written, but you can write 
> your own in whatever style you like.

6 years ago I wrote a perl regexp that did some magic.  The comment before
it...
  # It's lines like this that make people hate perl
The 10 line afterwards explained the magic.  After all, I would need to
read it again a few years later, so I needed to give myself all the help
I could :-)

(My best ever comment was "this came to me in a dream"; it was literally
correct - the answer _did_ come to me in a dream - and it took me 3 days
to work out _why_ that stuff worked!  I finally replaced the comment
with something more useful when I worked out what it did.  After all,
it was 10 times faster than my previous code).

The problem with perl isn't that you can write crap code in it; the
problem is that people take the "hammer" approach ("If I have a hammer
then everything looks like a nail").  The responses to the original
question are a perfect example; people wrote multi-line perl scripts to
do something that was possible in 1 line of sed (the people writing perl
didn't even write _efficient_ perl; dammit, -p flag people!)

I'm probably fighting a losing battle; I was shell scripting 17 years
ago when every fork/exec was expensive.  I cry when I see people writing
  grep | awk
type combinations (and don't start me on cat | grep).

Old geek statement: If you think perl is the answer to a simple filter
question then think twice.  You might be right, but it's likely smaller
faster tools already exist.  And I say this as someone who has written
1000 line shell scripts and even bigger perl scripts; perl is good for
complicated tasks, but rarely required for simple stuff.  Don't wield
your hammer because that's all you know.

In this case, everyone who responded with a perl solution needs their
hammer taken away.

-- 

rgds
Stephen



More information about the CentOS mailing list