Tuesday, September 13, 2011

I used Perl today

I have a confession to make: I used Perl today.

I know, I know. The deal was that I don't use a Mac anymore; I use Windows. I use Windows exclusively (well, I did get an iPad about 10 days ago, but besides that). So if I'm using Windows exclusively, that means I'm not using Unix/BSD/Linux, right? And that means I'm not using Perl, right?

Clearly Perl runs on Windows. There's ActivePerl, and I think everybody's favorite today is Strawberry Perl (which I haven't used, but probably should). But my usage of Perl is very often coupled with other things. Other Unix-y things. For example, today's task was to estimate the number of employees at my company -- not because anybody asked me to do it, but because I was curious. We happy to have a web pages that lists every employee, and a little analysis of the source of that web page will obviously reveal the number of employees. Easy, right? Well yes, when you're running Unix. You save the source to a file, cat it, pipe that to perl, search for a certain expression (or do it with grep or sed or something else), and you're done.

But on Windows... if you're me... you sit and think for a moment. Do I want to launch Cygwin? I don't really like Cygwin that much. And when I save this file from Internet Explorer -- or Notepad or whatever (no, I still haven't installed a real text editor, because my job is still mostly meetings and email), will I even really know where it saved the file? Windows 7 is kind of fast and loose with its shortcuts. It seems like I have 6 or 8 "Documents" and "Downloads" locations, which switch around randomly, apparently. I can never find anything.

So yeah, I launched Cygwin. I was then amused to find that I had yet to even install the Perl package in that Cygwin installation (I continue to be amused that it's not included in the base install). So I installed that (God bless the Cygwin installer for supporting IE proxy settings, since it's an autoproxy situation, though I still curse the Cygwin installer for being called setup.exe).

So, I got Perl installed, did my one-liner, and found that there are 426 employees. Oops, no wait... duplicates... pipe to sort, pipe to uniq... 223 employees. Done.

Now back to my non-Perl world.