Tuesday, June 14, 2005
Learning Perl, Again
I've got six months' worth of text log files to analyze. We need to verify that all the things happening in our machine are reflected in the printed reports that we generate. We need to extract the necessary data from all the old logs and compare it to the report's data. This looks like a job for Perl.
For you non-programmers: "Perl" is the name of a programming language that was designed to make it easy to extract data from files or to convert it to another form. You've probably never heard of it, but a lot of the web pages you view are generated by Perl programs.
For you programmers: Geez, I hate Perl. It's the only widely used programming language that is uglier than C++. It's just enough like C++ and the Bourne shell that it will trick me into trying things that won't work. However, for what it is good at, it is very good, so that's why I put up with it when necessary.
Unfortunately, I haven't used Perl for a few years, so I have to re-learn it. This will be the third time I've learned Perl—I learned it in college, then again after a couple of years of work, and now again. I'll have to stay up into the wee hours the next couple of nights reading my yellowed copy of the Camel Book, and then a few days struggling with syntax and library documentation until I get back into the flow.
I considered using the Python language instead, but Perl is a little better for this ripping-through-text-files kind of application. Also, I was concerned that if I used a "good language," I'd spend too much time making the code pretty. Since I barely know Perl, I'll keep it a lot simpler, focusing on just getting the job done as quickly as possible.
So, for the next couple of weeks, I'll be a Perl expert. Then I'll stop using it, and the knowledge will fade until I need Perl again. I hope it won't be soon.
You don't _have_ to spend time making Python look pretty. It does it on it's own.
I learned Perl 'in the way back' and had a really rough time of it. Python I grokked a lot easier (maybe because it seemed a lot like Pascal, the first computer language I learned).
Right now I'm learning Ruby. IMHO, Ruby is Smalltalk viewed through Python-lenses.
Anyhow, keep us posted as to your tales of woe. You write 'horror stories' like no one else... ;-D
Ruby struck me as a Perl programmer's attempt to re-implement Smalltalk. I hear a lot of good things about it, but my list of cool-languages-I'll-never-actually-use is already too long.
Second, to anyone who says "Perl looks ugly": go ahead and say that, but realize that the density of the language contributes to productivity, rather than distracting from it. The sigils to mark variables means that Perl can be upgraded to add new keywords as time goes on without colliding with your choice of variable names. Other languages have long-term problems: Perl doesn't suffer from that.
Terseness and other "ugliness" is something I'm willing to put up with when it helps. That's why I'm choosing Perl over Python for this particular application. FWIW, I generally use C++, so I'm obviously not enamored of prettiness.
Note to other readers: "merlyn" is one of the authors of "Programming Perl," "Learning Perl," and other important Perl-related books and articles.