Why I Love Perl

By | Posted at 19:50:3

I just wrote a complete XML-RSS aggregator that pulls in data from 137 feeds that are in a MySQL table, parses each feed, adds new entries into another MySQL table, and then changes the first table's entries to represent the last fetch time, last processing time (if the feed retrieval was successful), and last update time (if there were new entries added to the other table). I accomplished all this over today while doing other things, likely spending less than three hours on the actual project, including time studying a legacy MySQL table to which I am trying to conform.

That's why I love Perl. I am not someone who just loves to program, but Perl makes things efficient and sensible enough that at least I can get what I need to get working done in as little time as possible. cough Unlike cough PHP cough.

More on just how this fits into yesterday's post later.

Article Path: Home: work: Why I Love Perl

Re: Why I Love Perl

Tim, and what about Python? Do you think it is good as a Web development language?

Posted by Eduardo - Jun 24, 2005 | 15:25:5

Re: Why I Love Perl

Curious to see the code. given that php can also do regular expressions (haven't done Perl in a while) I'd like to see what Perl has to offer that PHP can't. No bashing, just curious. Its funny because I stopped using perl in favor of php for the exact reasons you like Perl.

different strokes I guess.:wink:

I remember being told that Perl is a great lang for “just getting things done” while PHP is when you want to keep doing them. Don't know if that's fair enough but I have seen it numerous areas.

Posted by Mark - Jun 24, 2005 | 15:55:44

Re: Why I Love Perl

Eduardo: I'm really not sure. I'm “functionally illiterate” in Python. Python isn't nearly as popular as Perl and PHP as a web language, though. Mailman is Python based, and quite nice, fwiw.

Mark: I don't know if I want to show my hodge podge. ;) Seriously, I'll show it to you when I get a little more done if you'd like to see it.

I use both PHP and Perl, but here are my reasons:

  1. It seems to be easier, with the way people write PHP programs, to inject code into a PHP program (it is all about bad coding, but note the PHP worms that have taken advantage of most major PHP programs using the very same technique for each one). One big issue involving this is that PHP programs tend not to die when there is an runtime error in the code, rather they keep chugging along, since they are being interpreted as the web server displays the results rather than the web server executing the CGI script and then reporting whatever it gets back when the script is done (this, of course, is why you can mix HTML and PHP in one file). Perl dies and causes a HTTP 500 error when something goes unexpected happens.
  2. Leading straight from point 1, PHP is much harder to run securely. Generally speaking, PHP runs as the same user as the web server (“nobody,” usually), giving it broad power to tinker with any file the web server has access to. Perl is run in a web hosting environment using su_exec, which makes it run under the user account, thus keeping rouge code from messing with stuff outside of the user's own account. There is a PHP su_exec, but from what I read, there are numerous problems with it, and the folks at cPanel advise web hosts using cPanel not to operate PHP su_exec.
  3. This leads into another problem: to prevent PHP from doing anything nasty, therefore, one must place PHP in safemode, which disables the ability to run shell commands from within a PHP script and breaks some PHP programs.
  4. PHP has regex, but it isn't nearly as elegant to deal with as Perl's regex… I have to type twice as much junk around each string to get it to run PCRE, which, of course, is a library that mimics the way Perl does things natively.
  5. Perl is much easier to use when dealing with files, especially when you need to lock the files… PHP does not support POSIX flock().
  6. CPAN is an invaluable resource with great documentation on thousands of modules to do just about anything.

Anyway, that's why I'm not fond of PHP. I'd be interested in hearing your reasons for going away from Perl. :)

Posted by Timothy R. Butler - Jun 24, 2005 | 16:46:43

Re: Why I Love Perl

To begin, I've always looked at perl as a Text manipulation lang. I know that's an insult given its true power but that's been my usage in the past; for me it went with Gawk perfectly.

Given that I started doing dynamic sites using ColdFusion, which is known for its rapid design speed, I didn't look to Perl to develop sites. Please correct me if I am wrong but Perl tends to be single programs while php resides in multiple files. For me this allowed easy dev with many people. Again maybe it just comes down to style and being used to DOD large scale developement.

I also remember when I was sent for training for Javascript and the first thing the instructor told us was how to stop people from injecting perl scripts into a form in order to hack a site. So for me, perl was the tool that enabled people to cause trouble. And one of the reasons I have a function which strips certain chars in my comments form to avoid such issues.

I'm also coming at web development from a different direction then you; I'm guessing. Most of my professional developement has been done behind firewalls in a corp setting where security “tends” to be a none issue, on windows machines. Please correct me if I am wrong but I don't think Perl runs on Win while PHP can. (See easyphp for example)

So do I have anything against perl, no. I don't have anything against any lang, ok I hate Ada but that's for another post. :twisted:

Posted by Mark - Jun 25, 2005 | 0:33:22

Re: Why I Love Perl

Well, you can develop with Perl pretty much the same way you do with PHP. For instance, this very blog has one front end script (for design reasons that aren't really relevant anymore), but all of the functionality is done by a bunch of different scripts that are “required” in and then sent on their merry way. Another one of my sites actually uses a bunch of different Perl scripts that are completely independent, other than calling on the same set of libraries, much in the same way PHP-Nuke or other php stuff is developed. I think it is mostly a difference in developer attitude — PHP developers are inclined to make more separate files, I think, since the original idea of PHP was to embed the code into actual web pages. A Perl hacker is more likely to think in terms of creating one backend script with a bunch of “masks” using the power of Apache mod_rewrite. :cool:

As I see it, the Perl way ™ is more like what you might do with C/C++, etc., whereas the PHP way ™ is a bit more like you might do with JavaScript. Perl “feels” almost like a compiled language to me in the way you do things. With Perl 6's Parrot, maybe someday it will be. Kinda hard to explain why I get that feeling, but…

Perl does run on Windows. That's actually where ActiveState got their start. MS paid them to port Perl to Windows. There are several other variants of Perl for Windows as well. At one point, when I was still running Windows, I had a fully functional Apache 1.3.x server on Windows 98 (and then Win2k) that had a full Perl install so that I could use it as a test bed for scripts.

I am coming from it from a much different direction. Partially, as a site owner who has had PHP sites cracked into due to some techniques I see utilized in PHP, and now also as a system admin that sees how hard it is to secure PHP on my server without crippling it. For example Gallery, my photo album tool, won't let me add new photos now that I secured PHP, since securing PHP requires removing the ability to run any type of *nix commands. :(

I don't dislike PHP… it is a bit easier to throw together a small site using it, although once things grow larger, I think it all equals out in terms of efficiency. For example, I can do Reg Ex and file processing much more efficiently in Perl (and Perl's LWP::UserAgent is absolutely amazing for implementing web crawling and XML::RPC stuff), but MySQL manipulation takes a bit more work in it — I usually include a subroutine that simplifies it to the level PHP has it at. Still, since usually I need some of all of those things in a big project, I probably come out about the same time wise. Given the caveats, I've stuck with Perl.

I must hear about Ada sometime.

Posted by Timothy R. Butler - Jun 25, 2005 | 1:45:57

Re: Why I Love Perl

I love perl because this past semester I took compiler. I was able to get everything in my compiler working in under 1000 lines with perl. The other people in the class that were using java were averaging something like three to four times as many lines of code…

As for php/perl, their both great languages and I use whatever makes since to use at the time. Though I often end up using php for web stuff because the ability to mix code and html saves time.

Posted by Brandon Wigfield - Jul 11, 2006 | 12:8:36

Please enter your comment entry below. Press 'Preview' to see how it will look.

Name:
Sign In to Your Account
User Name:
Password:
Location:
Homepage:
E-mail:
Subject:
:mrgreen: :neutral: :twisted: :arrow: :shock: :smile: :???: :cool: :evil: :grin: :idea: :oops: :razz: :roll: :wink: :cry: :eek: :lol: :mad: :sad: :!: :?: