Thursday, February 18, 2010

Adventures in Perl #1

For a long time I've wanted to be able to generate HTML from my delicious bookmarks so that I could sort them however I wanted. I figured that Perl would be relatively easy to learn, and would do the trick nicely. The images below are the final product after sorting my links by domain name:




















Overall, I'm pleased that I got my program working from scratch (i.e. from googling "perl download" to final debugging) in a single day. However I was surprised at how long it took to learn several simple routines (like pattern matching). I guess that's to be expected when learning any new programming language, especially when you're a newbie to the whole programming world!*

I still have a LOT to learn, obviously! I've barely scratched the surface, but I'm really excited about the power and simplicity of Perl so far. I can't wait to try some more projects. So, without further ado, here's how today went.

1) Download site: From ActivePerl for Windows XP, I downloaded the Windows Installer (MSI) for Windows(x86) which is what I have. Installation was a breeze.

2) Testing Installation: Using the DOS command prompt (Start > Run > cmd) I navigated to the \eg folder and typed example.pl and got the Hello World!

3) Concepts Learned (so far): Regular expressions, File I/O, for/while/if syntax, array building.

4) Resources used: Intro to Perl and Regular Expressions tutorial and Manipulating Arrays of Arrays in Perl. I definitely need to read these again..

5) Text Editor: Crimson Editor. This is a nice one because it highlights key words for a large number of programming languages. And please don't tell me I should be using vi. Sorry, my life is too short!

6) The code: The image on the left is what the code looks like. Click on image (or go here: or perl script #1) to see the text as a google doc.

7) What the code does: Pretty simple! It takes an HTML file in the delicious format (here) and sorts all the links alphabetically by domain name (voila). If you have a delicious account, you can export all of your links as an HTML file.

8) What I plan to do next: I want to sort all the links by TAGS (each link has this property if you view source).

* I suppose that's not fair. I've been programming in Mathematica and Matlab and LabView for almost a decade. I guess my memory of the learning curves for those has been wiped out! Even so, Perl is what I'm going to call my first "Real" programming language.

No comments: