128: Shining Perl-y White

I tried to build myself a presence on GitHub with some little projects (hint: I’m not a substantial enough coder for this to work). I got myself started with qlqw, a little script that writes the contents of your current Quod Libet play queue. I use my queue almost exclusively, because it allows me to just dynamically build a never-ending playlist. On the rare occasion that something forces me out of my session without a clean exit, the queue on disk isn’t updated and when I restart Quod Libet I end up staring frustratedly at a long list of pieces already played and dequeued previously.

I was already most comfortable with Python by the time I chose to write qlqw, but I figured I should keep my C flowing for my own sake; so I shouldered the burden of writing a thoroughly script-ish application in an awesomely low-level language like one uses a tiger tank to assault an anthill. The horrendous result, preserved for posterity, is bloated and ill-suited for C.

For the longest time I resisted rewriting it. The C implementation was good enough, I told myself. Today, I had just finished a midterm and scratched a quick-and-dirty sequential tagger out in Python (that worked brilliantly, I should add) when finally I scratched the itch and said, “fine, fine, I’ll recreate my monstrosity.” The part of my brain that throttled common sense and decency cried out with joy, but I got in the last word: “I’ll only do it in Perl.” I mean, I hate to let common sense reign in my twisted world.

Five hours before, I had just about zero experience with Perl (except with print statements to induce buffer overflows in homework). In the space of maybe two hours, with copious Bing-fu, I produced a working version of qlqw with half the number of characters (either way I write as many comments as I do lines of code) in Perl.

I’m actually quite shocked and a little pleased. It’s (in retrospect, not surprisingly) easier to grab environment variables, unescape URL-encoded strings, execute system commands, and to get command-line flags in Perl than in C. I could even arbitrarily capture the stdout stream of a system command into a buffer pulled from a hat. Much of my C code is a mess. One of the space-savers (piping the output of “quodlibet –print-queue” through cut) was something I really can’t believe I didn’t think of when writing the C version.

I look forward to more experiments in Perl (time permitting) and pushing more commits to GitHub on my little pet projects.



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s