Tag Archives: perl

… and back to Perl

For the last five years, roughly, I’ve been doing PHP programming, gradually forgetting the Perl that I knew, except when I wished PHP would do something that Perl makes easy.

One particular syntax I missed on an almost daily basis was:

foo( ) unless $bar;

It was therefore with some trepidation that I started on my new project, which uses Perl, mod_perl, and a heap of CPAN modules that I used to be very familiar with, but have, I thought, forgotten.

I’ve been very pleased to discover that I haven’t forgotten it, although some of it is pretty rusty. Perl’s use of different variable sigils ($, @ and % to denote different variable types) was welcomed back like group of old friends of whom you have fond memories, but sometimes confuse their names. If you know what I mean.

But it’s all coming back to me, and the various Perl colloquialisms are springing to my fingers.

I think that my years in PHP have benefited me, but I’m not very clear just yet in what way. The ability to jump back and forth between languages can make you perpetually confused, or it can make you stronger in both, depending on your approach. One hopes that you can learn something from the one to take back to the other, but that doesn’t always work out.

I am reminded on a regular basis, by support email, that I have a bunch of modules on CPAN which have largely languished while I’ve been in PHP-land. Of course, many of them have been superseded by better modules while I’ve been away. The Date ones, in particular, have almost all been superseded by the Perl Datetime project, which, although I helped start, Dave Rolsky has been heading for several years now. Maybe, if I’m lucky, I’ll have an opportunity to resurrect some of those modules and start playing with them again. Non-gregorian calendars, and traditions about different dates have long held a fascination for me, and I’d like to play with that again.

But, meanwhile, I’m learning the slang again, and since I’ve missed a half-dozen releases of Perl, I’m sure that it does even more weird and wonderful things than I did when I was a common face around the Perl circles.

Geek Arrogance and Chauvinism

I read with mounting horror Aaron’s post about the Ruby conference, and the various things that he linked to from it. Unfortunately, it’s an old and familiar story.

Unfortunately, it reminds me of attitudes in another community I used to be very involved in – Perl. Attitudes within Perl seem to have changed an awful lot in the last 10 years. I’m sure a lot of that had to do with the discovery that Allison Randall was smarter than any half-dozen of the rest of us put together. But, too, it had a lot to do with the examples of folks like Larry Wall and Casey West, who demonstrated by their actions that it was possible to be brilliant, but still be professional. This is a message that many boys (I hesitate to call them men) within the Ruby community haven’t grasped yet.

Having been involved in the planning of ApacheCon for the last seven years, I’m also horrified that the planning committee for a (seemingly) respectable conference would accept a talk that made no secret of the fact that it would use jokes about pornography to make its points.

I’ve written before about how pornography is treated as acceptable for public discourse. That was 6 years ago. At least in the technical circles *I* work in, this attitude has lessened, but not vanished, in that time. It is far less common for me to hear reference to porn in every day technical discussion than it was back then. I don’t assume that the people in question believe, as I do, that pornography itself is damaging. I think it has more to do with the realization that some discussions simply don’t belong in professional settings. When someone spends good money to travel and attend your conference, they deserve to be treated with professionalism and respect, not treated to a stream of pornographic images and sexual innuendoes.

And this isn’t just about alienating the women in your audience. Turns out that some heterosexual men actually believe that objectifying women isn’t a good thing. But even if you don’t accept that belief, you owe it to your audience to treat them with professional courtesy, and recognize that they are paying a LOT of money to attend a technical conference, not a peep show.

Shame on Matt for putting together this presentation. Double shame on GoGaRuCo for accepting this talk. Shame on the decent men in the audience (assuming there were any) who didn’t get up and walk out after the first slide. Shame on the chauvinistic boors who are defending Matt in the various forums where this is being discussed.

Turns out, in the real world, it actually matters if you’re a jerk. It’s time for the Ruby On Rails community to grow up and realize that being professional isn’t a weakness. But it would be grossly short-sighted to merely point the finger at them and not take a close look at the attitudes within our own communities – be they technical or otherwise – and seriously reconsider our common courtesy in the work place.

phptidy

Long, long ago, Steve Hancock gave us PerlTidy, which allowed me to quickly and reliably convert raw Perl code into code that abided by all of my coding standards, whatever they might be for a particular project. This was much goodness.

I even have a vim macro that allows me to select a block of text, type a key sequence, and have that code reformatted so that it is more easily readable, evenly indented, and just prettier.

For many years, I’ve looked for a similar tool for PHP. I’ve seen references to something that Coogle did, but I can’t actually find it, and it doesn’t completely sound like what I’m looking for anyways.

Apparently the problem is that the intermixing of form and function (html and php) that happens in php code, makes this a more difficult problem than just parsing and reassembling source code. I naively think that there must be a simple way to treat HTML as comments and ignore it, but seeing as I have not the vaguest idea of how to go about this, it’s kinda of condescending of me to make such claims. What do I know?

This morning I discovered that PerlTidy works, some of the time, to tidy up PHP code. And, of course, sometimes it doesn’t, because part of what PerlTidy does is inspect the Perl code itself, in order to determine how to format things, and PHP code doesn’t generally parse as valid Perl, except when it does.

When I was learning PHP, I observed repeatedly that it was almost exactly the same as Perl, in most respects, most of the time. This gained me many dirty looks from the “Perl is evil” PHP programmers I encountered, but, since language bigotry has never struck me as a survival strategy, I continue to maintain this belief. Indeed, this belief allowed me to uncover features of PHP that I don’t frequently see used, and aren’t very well documented, but I discovered blindly by assuming that PHP should behave the same as Perl if I need it to. And most of the time it does.

Ahem. Back to the point.

I find numerous postings on various blogs and mailing lists, where people are bemoaning the lack of a usable PHPTidy tool. I’m really curious why it’s a hard problem. I don’t understand what’s involved in doing this, in the least, either in PHP or Perl, so I have no real notion of whether it is hard or not. What gives?

Conference TShirts

The great conference TShirt is one that, if you have to explain what it means to someone who wasn’t there, takes 30 minutes, and leaves both of you feeling like it wasn’t worth the effort.

My canonical example of this is the shirt from the first YAPC I attended. It proclaims:

YAPC 19100
Laziness, Impatience, Hubris
Pick Any Three

This has embedded in it at least 5 inside jokes/references. Or 6, depending on how you count.

Most conferences I go to try to make shirts that live up to this level of cleverness.

A good bar is like good software: Open

Trillions and Trillions Served

But I don’t think folks often live up to the YAPC shirt.

I was thinking about this while doing laundry and I came across the “hAPI hAPI joy joy” shirt from the Yahoo booth at OSCon.

Perl stuff in svn

For many years, I worked on Perl date/time modules. Calendars – non-Gregorian ones, that is – held a great deal of fascination for me, and I wrote Perl modules for many of them. They’re all on CPAN, along with assorted other stuff.

Then, due to a variety of factors, mostly involving Apache, I gradually lost interest in writing Perl calendar modules, and those modules languished. At the same time, the great Perl DateTime module project started (at least in part because of my work, but mostly due to Dave Rolsky) and most of my modules became obsolete, and replaced with the better implementations that came out of that project.

I just rediscovered all my Perl date/time modules in cvs, as I was moving all CVS stuff over to svn. here they are, if anyone cares.

There’s some other stuff in there too, if anyone wants to poke around. If you want to submit patches, please feel free to do so. If you want to fork any of these projects and do something else with them, please feel free to do that, too, although I’d kinda like to know about it if they amount to anything useful.

Everything that you can get to in the public/ directory should be considered to be under ASL2 (Apache Software License version 2.0) unless explicitly stated otherwise.

Perl lightning talks

The Perl lightning talks have been a staple of the Perl Conference, and, later, the O’Reilly Open Source Convention, for as long as I’ve been attending it. And YAPC, too, although I haven’t been to YAPC in many moons. They were somewhat different this year. Not hugely, but subtly.

MJD observed that, when he started them, the purpose was to get folks who would otherwise not give talks to give brief presentations in a low-stress environment. 5 minutes is enough to get a taste of public presenting, but not long enough to get too terribly intimidated.

Over the years, it became a bit of a sideshow, with elaborate presentations, complete with slides and sound effects. And of course MJD as the MC, complete with funny hat and gong. And so folks who wanted to give a five minute “here’s what I’m working on” or “here’s my cool idea” talk were overshadowed by the brilliant presentations by Audrey Tang and Andy Lester and the like. Also, talks lean towards the comic routine rather than the technical talk. Indeed, technical lightning talks tend to get heckled on IRC, and yawned through, waiting for the *real* lightning talks.

We started doing Lightning Talks at ApacheCon a few years back, and they have become part of our conference culture. We, too, tend to favor the entertainment talks rather than the technical talks. That’s fine, in that it draws a crowd, and folks hear interesting ideas, and it’s a great community event. But we need to remember what the initial purpose of lightning talks really is – to give folks a shot at the mic, if only for a few minutes.

Of course, I don’t run the lightning talks, so feel free to ignore me. 🙂

Delicious library on your website, sort of

I’ve hacked together a few dozen lines of Perl that transform your Delicious Library XML file to HTML pages. It is by no means complete, but if you care, then it will give you a starting point. It uses XML::Simple, which has prerequisites of XML::SAX and XML::NameSpaceSupport.

Put this in “/Users/username/Library/Application Support/Delicious Library”, mkdir HTML, and then run it. It will generate files in that HTML directory, one called index.html, and then one per book.

Patches welcome. I’ll be doing more useful things with it when I have more time to hack on it. Apparently I just spent 2 hours on this. Sheesh.

delicious2www.pl

HJTI license. Will eventually have templates, so that I don’t have to listen to people complaining about how ugly my HTML is. It doesn’t handle the case where you don’t have cover images. And it currently only does books. No particular reason for that.

Example output

—————————————

Update: Version 1.4 does movies and music, orders the output by title, and has at least a nod at documentation.

Permalinks

WordPress comes with a nifty feature called Permalinks, whereby you can have links to your articles by name, rather than by the icky ID number.

I’ve never done that, because the rewrite rules necessary to make it happen are deeply inscrutable.

Well, since I’m monkeying with mod_rewrite stuff anyway, I thought that making a permalink thingy that I can actually understand would be a good example of a RewriteMap rule. So, here it is.

This is a first draft, and may have some problems. I already know one problem, and that is that RewriteMap can’t be used in .htaccess files. That’s not a problem for me, but it is a problem for a significant number of folks that use WordPress. The only way around that is to get your server admin to add a RewriteMap line to the main server config file, pointing at your map program. That problem may be insurmountable for some folks.

Anyways, in your config file, you put:

RewriteMap wp_permalinks prg:/somewhere/bin/wp_rewrite_map.pl
RewriteRule ^/perm/(.*) ${wp_permalinks:$1} [PT]

The file /somewhere/bin/wp_rewrite_map.pl looks like this:

#!/usr/bin/perl
use DBI;
$|=1;
my $dbh = DBI->connect(“DBI:mysql:wordpress:dbserver”, ‘username’, ‘password’);
my $sth = $dbh->prepare(“SELECT ID FROM wp_posts
WHERE post_name = ?”);
my $ID;

# Rewrite “permalink” style links to article IDs

while (my $post_name = <STDIN>) {
chomp $post_name;
$sth->execute($post_name);
$sth->bind_columns($ID);
$sth->fetch;

print “/wordpress/index.php?p=$IDn”;
}

This article, for example, has the URL of https://drbacchus.com/perm/permalinks

Is that a camel?

There was a guy in line at the security check at the airport wearing a Perl Mongers T-shirt. I asked him, indicating the shirt, if he was a member of a local Perl Mongers chapter.

His response?

“No. I don’t even smoke. Someone gave me this shirt.”

In other news, I just paid $10 for a small sandwich, a bag of chips, and a bottle of water.

Magnetic essay

Long, long ago, I got a set of those magnetic words. Except that these ones were Perl words. Presumably so that you can write Perl code on your refrigerator.

Well, thus far, I haven’t really had any facility in any office that I’ve had to put them up. Now I have a steel cabinet in my office. So the entire front of it is covered with words. It’s quite alarming. And, this morning, I wrote a brief summary of my vacation. Apparently I’m Indiana Jones:

select time
dump tie

BEGIN in library
study map
pack

seek my keys
@ $ % & #
no use

harness camel
exit, split stat
continue until i DESTROY my backend
STOP

goto crypt
open crypt
kill panther
Safe !

return home
unpack
sleep

And, no, I have no idea why there’s a panther in there.