Neil Turner's Blog

Blogging about technology and randomness since 2002

Slowly Learning Perl

Screenshot of BradLog-Perl Last night I threw myself into my copy of CGI Programming With Perl and hashed away at getting the Perl version of my project moving in some sort of positive direction (instead of it going nowhere slowly like it has been of late). At first I was getting nowhere, spending half an hour swapping code in and out before remembering that you can’t run a Perl script when the file permissions are only 644 (doh!), but after another hour or so I had a public frontend that was almost functionally equivalent to the PHP version. The changes I need to make now are something which mimics PHP’s nl2br() function (converts newlines in a piece of text to HTML line breaks, i.e. <br />), which will probably require a regular expression, and the replacing of a few constants with variables.
But at least now I don’t hate Perl as much as I did, though I can say that Perl is much, much slower at generating pages than PHP is.

5 Comments

  1. Are you running both as CGI, or as mod_[foo]?
    s/\n/<br \/>\n/g
    should do as an nl2br() replacement.
    I have to agree with your overall gist, that PHP is much nicer than Perl for webDev. Mind you, it’d be a poor show if it wasn’t, what with PHP being designed for munging HTML.
    What won me over was that you can do OOP really easily. If only it had stronger typing (or at least hinting), it’d be nigh on perfect.

  2. Just in case this helps, i was writing a similar script just today;
    $message =~ s/\s+$//s; #remove trailing whitespace
    $message =~ s//>/g;
    $message =~ s/\n+/\n/g; #disallow multiple newlines in a row
    $message =~ s/\n//g; #convert newlines to
    ‘s
    if you need any help understanding this stuff, feel free to email me 🙂

  3. If you’re transitioning from PHP, you might want to look at Perl’s “Template Toolkit” (http://www.tt2.org), which provides for a very nice embedded language, including filters like you want for HTML.

  4. Mark: I’m guessing it’s CGI because the scripts can only run out of the cgi-bin folder on the web server. Thanks for the regular expression though, and to Anko too. 🙂
    Randal: Unless that’s included as standard in Perl it’s unlikely I’ll be able to use it since it’ll have to be installed by the techies at the university. I don’t have shell access to that server, and can only use external modules if they’re pure Perl. HTML::Template looks interesting though.

  5. Ooo, you mentioned the BlobJournal. To be honest, it’s not really that great, and I’m working on a new blogging package. It’s vapourware at the moment though.