It’s a battle between Man and Machine … and while the Man’s not winning, I’m not doing all that badly.
My first encounter with trying to get my Perl scripts to execute on any Unix box was a brutal massacre that left bits of my geeky ego scattered across my desktop. Like any good general though, I knew when to fall back and regroup. I did exactly that, and decided to try and eliminate as many potential problems as possible.
First, I wanted to get things working on my Power Mac. I downloaded the Apple Developer’s Kit, a free download (registration required) which is essential for installing the latest version of mod_perl. With the kit installed, I followed the instructions outlined in Apple’s article “Installing Perl 5.8 on Jaguar”.
Then I began testing scripts. First I tried the “printenv” Perl script included with Mac OS X through the Apache cgi-bin I’d activated earlier. Then began trying to edit a copy of it using BBEdit, a standard XHTML/script editing tool on the Mac platform. I gutted the original script, keeping only the headers in a hope to get the thing to run through my Mac’s cgi-bin.
It didn’t work. Damn it. I tried it on my Web server at work. And it still didn’t work. After clucking silently to myself, I decided to fall back even further. I ditched BBEdit in favor of an even more basic editor, Simple Text (which is the Mac equivalent of Windows’ Notepad. I wrote a quick “Hello world!” script, switched to Terminal, assigned it the proper priviledges and tried to run it from the command line.
It worked. Curious. I tried running it through my cgi-bin. It failed. Damn it. I looked at my Apache error log using the tail command (tail /var/log/httpd/error_log to be specfic) and noted that Apache was bitching about incomplete headers. Weird … but at least it was working at the command line.
I did the same thing with a file I created in Windows Notepad, with identical results.
Then I fired up BBEdit again, wrote another “Hello World” script and tried to run it at the command line … and it failed. Ah ha … clearly BBEdit was screwing with me … something about the way its normal files were saved was causing Perl to barf. So I experimented with the “Save As” settings and discovered that if I forced BBEdit to save the document as plain text using Unix formatting, my script would run.
In hindsight, this was the major problem — the BBEdit formatting. Installing Perl 5.8, while educational, wasn’t really necessary (as I later learned by trying out a properly-saved BBEdit script on my iBook). Still, I’m glad I did it — it could prove useful later on, and its always good to be running the latest stable build.
Cool. But I still couldn’t execute my programs via the cgi-bin. I started hunting through my Learning Perl book and found at least a hint of the answer. When I copied down one of their CGI-specific Perl programs, and ran that, it worked. This puppy clearly had some commands in it that was forcing Perl’s CGI module to parse the code properly. I’m not exactly sure what those commands are, but it has something to do with a here document and end token.
Not knowing why I’m screwing up is annoying … but I am making progress. At least one script executed on the server, and that means I’m on the right track. Now I’m going to go back to the beginning of the book and start from scratch, hopefully picking up enough to understand why my cgi stuff fails (or succeeds).
All of this may sound like a hell of a lot of work and admittedly it involved a heck of a lot of problem-solving, but for me, this what being a geek — no, being human — is all about. Find a problem. Attack that problem. Solve that problem. Repeat. Without this sort of hunger — be it to discover fire, invent a new kind of metal or solve a programming problem — we’d still be living in caves.