Perl <—> PHP

Posted by dminor Sat, 07 Feb 2004 22:45:00 GMT

A while back, one of the guys I chat with occasionally sent me a link showing how to translate a task in both Perl and PHP side by side by Robert Kline. I printed it off and read it last night while at McDonald’s letting the boys burn off some winter energy. I’ve had some interest for a while about learning Perl for a number of reasons that I won’t go into.

All in all, Perl does things more succinctly as I see it. There are examples of where PHP ties things up better (faster), but for the most part, it takes several more characters to do a task than in Perl. Typically, that’s because the functions are more descriptive in PHP. For instance:

In Perl: $s =~ s/^\s+|\s+$//g;
In PHP: $s = rtrim($s);

But what excites me the most about Perl is the section on HTML Elements. Dropping variables into HTML is one of the things that excited me about PHP when I was looking for a scripting language to add to my skills coming from just a designer standpoint. Being able to switch between HTML/PHP modes in a script was nice to keep the two modes separate in my head. What has frustrated as I’ve switched to almost exclusively scripting instead of designing is that switching between modes to output PHP variables took a lot of keystrokes! and it seemed that writing the HTML for something like a form could be written by hinting to PHP what I wanted to do. I’m sure there is a PEAR package that does this, but I’m not really looking to continue developing much in PHP, so I haven’t looked.

What Kline’s comparison points to (if I’m reading it correctly) is that these lines should output the same thing:

In Perl: submit({value=>"yy"})
In PHP: <input type="submit" value="<?php echo $_POST['yy']; ?>">

My only complaint with what I see right now (and I admit I haven’t studied this much at all) is that the output of the Perl package is HTML 4.0. I would hope that there is a package that outputs XHTML too. I’ll have to look into this more.

All in all, this makes me excited about picking up Perl as another tool for development. I don’t want to start a debate about whether Perl or PHP are better. I just want to know both.

Posted in  | no comments

Comments

Comments are disabled