Skip Navigation

Perl

In an effort to “learn” Perl, I applied it to building the pages of this site by creating a crude content management system. OK, one lousy script hardly constitutes a “system,” but it works. The system involves writing the content of each page complete with HTML tags. Then a Perl script, which uses Text::Template and a MySQL database, builds the menus and produces the finished page.

Earlier adventures follow below...

Upgrading Perl. Opened the CPAN shell perl -MCPAN -e shell. autobundle which fetches a current list of authors, packages, and modules, then chugs for a while and outputs a list of current modules in their current latest version numbers. When it's finished, it makes a snapshot: Wrote bundle file /Volumes/tony/tony/.cpan/Bundle/Snapshot_2004_06_26_00.pm Then immediately tried to reinstall it: cpan> install Bundle::Snapshot_2004_06_26_00 OK until Warning: prerequisite IO::Zlib 1.01 not found. Writing Makefile for Archive::Tar ---- Unsatisfied dependencies detected during [K/KA/KANE/Archive-Tar-1.10.tar.gz] ----- IO::Zlib Shall I follow them and prepend them to the queue of modules we are processing right now? [yes] I answered yes Stuff about latest version. Permission problems... should have run as sudo? (from newsgroup cpan> b force install recompile) Installing autobundle was probably a mistake. Now getting perl 5.8.4 source, on Desktop, expand with Stuffit Expander. Ran instructions at http://search.cpan.org/~nwclark/perl-5.8.4/INSTALL sh Configure -de make make test make install seems to work fine. Ran cpan, but it was like it was the first time.

Wednesday, March 31, 2004

Brand Spanking New Perl... By Accident

After my last adventure with Perl, I was wishing I could upgrade my Perl 5.8.2 to 5.8.3 without breaking anything. I had learned that the “autobundle” command of CPAN can create a giant archive module of all your modules to make reinstallation of them easy after an upgrade.

In testing autobundle, however, I ran into an immediate problem. While I could easily create my autobundle, I couldn't re-install it. The message I received was: “Warning: Cannot install Bundle::Snapshot_2004_03_31_00.pm, don't know what it is.” I Googled for help with this, but came up dry. There's a lesson to be learned here. Whenever you have a problem that no one else has ever had (apparently), it means you're probably doing something incredibly boneheaded and not encountering some rare bug. This was true in my case, as well. Perl modules and bundles have extensions of .pm, but in CPAN you don't use it. All I had to do was chop the extension off of Snapshot_2004_03_31_00.pm and all was well.

In reading the output from the reinstallation, there were some modules it was having trouble with, so I tried installing one manually, using “force.” This particular module is reportedly included with the new version of Perl, so CPAN merrily set about installing Perl 5.8.3! Not what I had in mind, of course, but it all went well. I have a shiny new Perl and all updated modules. Ain't technology wunnerful?

Thursday, January 30, 2003

Congratulate me. I'm writing this entry in my brand-new "content management system." Regular reader of these pages will remember that I have been playing with Perl and the Perl module Text::Template in an attempt to eliminate Dreamweaver from my work flow, such as it is. First, I rewrote the most complicated bit--the code that creates the custom navigation menu on each page--and this morning slapped together a template to finish the job. What I have so far does indeed eliminate Dreamweaver, but if I wanted to change the template, it would be tedious. Another disadvantage is that there is now an extra step whenever I edit a page. Before I would just open my local copy of the live page, change it, save it, and upload it. Now I edit the "content" page (which includes embedded HTML) and have to run a Perl script to render it through the template. It's only one extra step, and BBEdit's Unix Scripts menu makes it painless. It's far from an ideal system however, so for now I'm only going to use it on one page as I go about making other behind-the-scenes changes.

Tuesday, January 28, 2003

Last night I reached the first milestone in a new initiative to move away from my dependence on Dreamweaver. I recreated the code which builds the navigation menu on the left side of each page in Perl (the code was originally written in AppleScript). This was my first real use of Perl beyond simple "Hello World" kinds of programs. I'm not sure my Perl code is all that idiomatically "Perlish," but the resulting script was significantly shorter than the AppleScript version. My plans now are to write a new site template and related files and using the Perl module Text::Template to actually build the site. I don't have any plans to redesign the appearance of the site ('cause I don't have any design ideas), but I do want to make the site more accessible, per Section 508 and the recommendations of Mark Pilgrim found at Dive Into Accessibility. None of the pages in the site use any of the new code yet, but it won't be long before you will no longer see such Dreamweaver cruft as "#BeginEditable" in the HTML source. Meanwhile there are still a number of challenges to overcome. While it would be easy to replicate Dreamweaver's template capability in Perl, I would be doing just that--replicating--and only that. It seems as if using a database or <shudder> XML are the only alternatives that could deliver more flexibility. No wonder Movable Type (et al) is so popular!

Wednesday, January 22, 2003

In searching for information regarding Perl, I've come across a few vague warnings that installing Perl 5.8.0 will somehow "mess up" my Mac. I don't doubt it, but so far, so good. I'm not even sure that I don't still have Perl 5.6.0 lurking in the shadows of my machine somewhere.

What I've been doing is looking into the possibility of maintaining my site using Perl instead of AppleScript. I found an interesting article at Perl.com called "Choosing a Templating System" which compares the various Perl modules that provide templating facilities. Based on this article, I decided to take a look at a module called Text::Template, so straight away I needed to learn how to install Perl modules. It should be easy, but like everything you do with computers for the first time, nothing went smoothly.

There is a module that expedites downloading and installing other modules. It's called CPAN.pm. I already had a fair number of modules on the computer, including, as it turns out, CPAN. In fact I had two versions of CPAN in three locations: Version 1.52 at System/Library/Perl/CPAN.pm and version 1.61 at /usr/local/src/perl-5.8.0/lib/CPAN.pm and also at Library/Perl/CPAN.pm. I tried running CPAN and got the shell prompt cpan>, but couldn't get anything but errors. Well, "h" for help worked OK... I decided that I would try reinstalling CPAN itself, but without CPAN, I would have to do this manually. Catch-22.

I downloaded the latest version (1.63) from CPAN's directory at Perl.com; the specific file was named CPAN-1.63.tar.gz. In the process of downloading, the file was somehow automatically unzipped from .gz to .tar. I then ran tar -xvf CPAN-1.63.tar, which created a directory "CPAN-1.63" just full of stuff. I cd'd to this directory where I found "Makefile.PL." So far, so good. The next step is to run perl Makefile.PL, which returned:

Checking if your kit is complete...
Looks good
Writing Makefile for CPAN

Thanks for the compliment. The next step is to run make, which returned:

cp lib/CPAN.pm blib/lib/CPAN.pm
cp lib/CPAN/Admin.pm blib/lib/CPAN/Admin.pm
cp lib/Bundle/CPAN.pm blib/lib/Bundle/CPAN.pm
cp lib/CPAN/Nox.pm blib/lib/CPAN/Nox.pm
cp lib/CPAN/FirstTime.pm blib/lib/CPAN/FirstTime.pm
cp cpan blib/script/cpan
/usr/bin/perl "-MExtUtils::MY" -e "MY->fixin(shift)" blib/script/cpan
Manifying blib/man3/CPAN.3
Manifying blib/man3/CPAN::Admin.3
Manifying blib/man1/cpan.1
Manifying blib/man3/CPAN::Nox.3
Manifying blib/man3/Bundle::CPAN.3
Manifying blib/man3/CPAN::FirstTime.3

Then I ran make test just to be sure all's well. The result: "All tests successful." Who am I to question success? Finally, I ran sudo make install, which produced:

Installing /Library/Perl/CPAN.pm
Installing /Library/Perl/CPAN/Admin.pm
Installing /Library/Perl/Bundle/CPAN.pm
Installing /usr/local/share/man/man1/cpan.1
Installing /usr/local/share/man/man3/Bundle::CPAN.3
Installing /usr/local/share/man/man3/CPAN.3
Installing /usr/local/share/man/man3/CPAN::Admin.3
Installing /usr/local/share/man/man3/CPAN::FirstTime.3
Installing /usr/local/share/man/man3/CPAN::Nox.3
Installing /usr/local/bin/cpan
Writing /Library/Perl/darwin/auto/CPAN/.packlist
Appending installation info to /Library/Perl/darwin/perllocal.pod

At this point, I assumed that my troubles were over. Ha! I ran CPAN by entering perl -MCPAN -e shell and at the cpan> prompt, entered "r." This returned: All modules are up to date for /./ Whatever that means... but, sounds good to me. Then, just as CPAN suggests when you first invoke it, I tried install Bundle::CPAN. This didn't work very well. CPAN said:

File::Spec is up to date.
Digest::MD5 is up to date.
Running install for module Compress::Zlib
 
  The module Compress::Zlib isn't available on CPAN.
 
  Either the module has not yet been uploaded to CPAN, or it is temporary unavailable. Please contact the author to find out more about the status. Try 'i Compress::Zlib'.
Running install for module Archive::Tar
 
  The module Archive::Tar isn't available on CPAN.
 
  Either the module has not yet been uploaded to CPAN, or it is temporary unavailable. Please contact the author to find out more about the status. Try 'i Archive::Tar'.
Bundle Bundle::libnet not found on disk and not on CPAN.
  Maybe stale symlink? Maybe removed during session? Giving up.

Hmm. I don't know what this means, but "giving up" sounds ominous and final. I was also very surprised that neither Compress::Zlib nor Archive::Tar were available on CPAN. Of course, they are on CPAN; something else must be wrong. Next I tried reload index and that seemed to clear things up. The first package I tried to install failed with permissions problems during the final phase. Sigh. At this point, I gave up on CPAN.pm and went ahead and installed Text::Template manually, just the way I did for CPAN.pm. It worked just fine.

 

Wednesday, December 18, 2002

After installing Jaguar, I waited patiently for a compatible version of Fink to be released. Version 0.5.0a was released on December 9. I deleted my existing Fink installation following instructions in the Fink FAQ. This was no great loss, since I had almost no Fink packages except for XFree86 and the web browser Amaya, which is what got me started with Fink in the first place. What's all this have to do with Perl, you ask? Well, Fink uses a Perl script to install so Perl has to be working properly to install Fink. When I went to install Fink, however, I didn't get very far, and the installer halted with this error:

dyld: perl Undefined symbols:
_PerlIO_getc
_PerlIO_putc
_Perl_PerlIO_read
_Perl_PerlIO_write
_Perl_bytes_from_utf8
_Perl_call_sv
_Perl_eval_sv
_Perl_get_sv
_Perl_hv_iternext_flags
_Perl_hv_store_flags
_Perl_safesysfree
_Perl_safesysmalloc
_Perl_safesysrealloc
_Perl_sv_2pv_flags

 

That led me to think there was a problem with my Perl. I quickly learned that I have two versions of Perl. If I just type perl -v, I found that my default version is 5.6.0, which is what is installed by OS X (Jaguar). But I also discovered that I have 5.8.0. (I must have installed 5.8.0 myself when it came out and then forgotten about it.) I had 5.6.0 in /usr/bin (with additional stuff in /System/Library/Perl), and I had 5.8.0 in /usr/local/bin (with additional stuff in /Library/Perl). Since my path doesn't include /usr/local/bin, when I call perl, I am getting 5.6.0. 5.6.0 wasn't working correctly, since Fink wouldn't install, and I didn't feel confident about changing my $path to invoke 5.8.0, so I decided to reinstall 5.8.0 based on these excellent instructions at Apple's Internet Developer web site: Installing Perl 5.8 on Jaguar. Note that Apple's instructions are at odds with a Perl 5.8 version they have made available in Downloads/Unix & Open Source. This is perhaps a binary (I'm not sure) "that will not overwrite or conflict with the version of Perl that is supplied with the operating system. NOTE: Conflicts have been reported if you currently have Fink installed on your system." Maybe I should have used this one. Oops.

According to the instructions, the default install location is /usr/local/bin. This seemed ideal, because I had read that OS X uses Perl itself and, because there are some significant differences between 5.6.0 and 5.8.0, I didn't want OS X using the wrong version. (Don't ask me why I wanted 5.8.0. I just have to have the latest and greatest, I guess.) Anyway, the installation went smoothly, but after I was finished, I no longer had Perl 5.6.0! Both /usr/bin/perl -v and /usr/local/bin/perl -v returned 5.8.0. I don't understand that, and it worries me. But Fink installed correctly, so what the heck... There is still a file in /usr/bin called perl5.6.0, which says it is (surprise!) Perl 5.6.0. Maybe I still have Perl 5.6. Somewhere.

 

March, 2002

Finished up a Perl class at work in early March, 2002...

If I ever come back to Perl, I want to remember what I thought looked like some good books to get at the time. The current version of Perl is 5.6.1, I believe.

We have a number of Unix systems here (Clix on Intergraph, SGI, and aix on RS/6000). Versions of Perl I've seen are 4.1, 5.004_04, and 5.6.1.

Tom Christiansen maintains a collection of book reviews on perl.com called "Camel Critiques." This has been my main source of information for book reviews. Since Tom co-wrote Programming Perl with Perl's creator, Larry Wall, I feel he is an unimpeachable source. The books I would like to get are:

  • Programming Perl (natch)
  • The Perl Cookbook
  • MacPerl: Power and Ease

Another recommended book not included in Camel Critiques is Elements of Programming with Perl by Andrew L. Johnson.

Perl Style by Tom Christiansen.

Posts in “Perl”

February 28, 2009

Broken Perl Following Leopard Security Update

I started getting errors about “weak references” from a Perl script that used SOAP::Lite and XMLRPC::Lite modules after installing Security Update 2009-001 recently. Many people reported problems with their Perl installs, and the most common advice I found was to reinstall the IO module manually, which I did (see macosxhints), but that didn’t fix it. Another affected module was Scalar::Utils, which I also installed manually, and it did fix the problem.