Perl: My secret weapon

This week I have been extremely grateful that Perl is in my bag of tricks. There are two distinctions that you can make in the world of programming: people who work on lengthy projects, and people who work on short projects. I fall into the latter group, most of the time. Frequently, projects that I work on last less than a day.

Earlier this week, my boss asked for my advice with a project in Access; I gave him a suggestion of two. The next day, he came to me and asked me to do it. The SQL code he had written worked, but it was taking over four hours to process the 97,000 plus records. Access tends to be rather speedy, so I took a look at his query. While appeared simple, it essentially did a massive correlated query with a group aggregate function back to the original; not exactly efficient.

Not being very familiar with Access at all (I avoid it like the plague, to be honest), I looked for another way to do things. I really cannot stand Access. It is too "basic‿ and "helpful‿ to accomplish any real work at all, and relational databases are far too difficult for the average user to understand. It is a crippled product, in my mind. Not from a technological standpoint per se (although it is technologically crippled too), but from a suability standpoint. You simply cannot accomplish tasks with it very well.

Me being me, I immediately dumped the Access tables to CSV format, loaded them up into MySQL, and re-ran the query with the needed modification. While it did work and worked just as well as Access, it was only marginally faster. So I dumped the data back out of MySQL to a true CSV file (Microsoft products have a hard time with making a good CSV file) and decided to get buck wild with Perl on it.

Thirty minutes later, I had a Perl script that did in literally five seconds what took Access over four hours to do, and MySQL was probably going to chew on for three to four hours.

That's the magic of Perl.

Perl is my secret weapon. It lets me do in a fraction of the time what other coders can spend all day on, for those small utility projects. It executes insanely fast for an interpreted language. It has an unbelievable number of nice libraries. And it has a great community.

I cannot count the number of times that I spent a fraction of the time needed for other tools to write something in Perl that ran faster than the other languages would run it. Whenever I get a dinky request for a one-off task, my first thought is always, "can Perl do this for me?‿

Indeed, the only real problem that I have with Perl is that its syntax for complex data structures like arrays of hashes of arrays can be a bit confounding. I am currently working on a short Perl script that I spent nearly a day wrestling with over these kinds of syntax issues. But that aside, Perl is a fantastic tool for the quickie jobs.

How do you use Perl to simply your life?



Justin James is the Lead Architect for Conigent.

Editor's Picks