Perl versus PHP 5

by brian d foy

At the Open Source Convention, I heard a lot of Perl people bemoaning PHP 5. I've never really had anything against PHP. I don't care to use it, but that's just my preference. Some people really hate it though.

I figure that they must have something that people like if it is so popular. I figure it is easy to use and widely available. Perl was once easy to use, but lately I've seen a lot of complaints about how hard it is to install modules and whatnot.

What have we missed that the PHP folks clued-in on? You might be tempted to bash one side or the other, but I'd really like to hear people talk about the good things that PHP does for its users so we can learn from it (and make our stuff easier to use).

37 Comments

aristotle
2004-08-18 23:57:44
Brain-dead simple
I think it's mostly two points:


Firstly, the fact that it's really easy to offer mod_php on shared webhosting accounts. You don't see mod_perl-enabled webservers offered for 5 bucks a month.


Secondly, it's an overgrown templating system. People want to make dynamic webpages; they want something that lets them do that quickly and dirtily. They don't care about how well it is designed and engineered so long as it's just dead simple to get into. It's crap, but it lowers barriers to entry. In Perl, you'd have to learn the language and a templating system and a database interface and all of that separately. With PHP, you just learn a wishy-washy conglomerate of bits that makes your dynamic webpages work even if you barely have any clue at all. A few years ago, beginners would hack together horrible CGI code in Perl. Now they use PHP, and their concoctions are just a little less awful. Matt's Script Archive is dead; long live PHP.


It's a classic example of "worse is better".

quijote
2004-08-19 02:52:20
Brain-dead simple
Did you really expect anything other than rants in the replies?


Aristotle is a philosopher and obviously a battle hardened man. Obviously there is no place for templating - blogging software is all the plebs need. Already configured obviously. I actually think that html or php (substitute in many words here!)is valuable since it is often the way new users discover a way of interacting with a computer via code for the first time. And if you have already got good design skills and are comfortable with languages - you are big enough to either use it well or choose a different option.


teejay
2004-08-19 03:49:17
its the applications
PHP has a lot of applications, some of them very good and very easy to install and setup.


The problem isn't that PHP is easier than Perl -- Perl is as easy to learn as PHP, but rather it has an image of being easier combined with applications that draw in new users.


Perl doesn't have any equivilent to SquirrelMail or many other very good PHP sites. Perl has also had so much Mud slung at it about being hard that PHP zealots can make claims about it being much easier and lazy or uninterested people will never see how wrong they are. Python also has this effect.

Baggy
2004-08-19 03:53:43
Perl vs PHP


As a user of both Perl and PHP I see the advantages and disadvantages of both.



At work - I code exclusively in Perl - mainly because of the nature of the project - which has a Perl based API - and the scripts are relatively complex.... but the output relatively simple



For fun I use mainly PHP - except for the few cases where I cannot get PHP to do what I want it... and I don't just "hack together simple scripts"... or where I want to play around with
modifying the Apache call cycle. (User authentication, logging etc...)



For most of the tasks that I perform PHP it is simple, has the calls I need built in - with no need to search around for modules to do what I want, and is a much more rapid development environment than Perl

raster
2004-08-19 06:53:28
Perl and PHP
Perl and PHP have very different cultures. I've been using Perl for years, and just recently started getting into PHP a bit more. PHP is pretty easy to get started with.


I think what PHP has to it's advantage is that it's simple for people to go from building simple static web sites, to slowly adding in some PHP code, and just changing the file extension from .html to .php - it sort of sneaks up on people. I don't think Perl has an equivalent. Someone wanting to do dynamic web sites with Perl is going to have to just through a number of hoops, and guess on the best approach.


I still use Perl daily for heavy-duty data manipulation, but I am starting to see the lure of PHP for dynamic web sites...

tiffanybbrown
2004-08-19 06:54:50
I think PHP is easier to pick up if you're a non-programmer


I'm not a programmer by training (I'm completely self-taught), so for me, Perl was scary.




My moment of conversion: I was trying to write a simple CGI form-to-mail script in Perl, and couldn't get it to work, even by following an example from a book.




I tried to do the same thing in PHP, and did it in a day.




Sure it was an insecure, completely crap script. But it did what I needed it to do in the time-frame I had. Been a PHP fan ever since.




Looking back, I chose PHP for these reasons:




  • Easier to code simple stuff. For example, a mail() function is built-in. No need to parse the message string.


  • No need to set a variable type (although you can). PHP figures it out (not always a good thing, but surely a less-complex thing).

  • PHP is made for the web. PHP scripts are HTML pages by default. No need to type "Content-type: html ..." or-what-have-you unless you want something other than HTML.

  • Well-documented. Perl resources seemed a bit scattered at the time (keep in mind that this was almost four years ago and programming was still jibberish to me). RTFM means nothing if you're not sure where the FM is or which part of the FM you need.

  • PHP is darn-near everywhere and fairly full-featured without having to install other modules. (Do I need another module? Which module do I use? And what's a module anyway? I'm on a shared server so can I even install a module?)



I'm not sure what Perl can do that wouldn't fundamentally change the language. But understand that its power and flexibility -- 'There's more than one way to do things' -- is also its curse for the non-programmer.


peterhickman
2004-08-19 07:07:57
Quickstart PHP
PHP's great advantage is that it does so much out of the box. You want sessions, you've got it. It's built right in.


With Perl instead you have many and varied solutions and that can be the problem. For starters you will have to install extra software no matter what, not with PHP, and that assumes that you can make a sensible choice from the various options. Then you have to configure it. Yes the various Perl solutions to Apache sessions give you more flexibility and scale better but damit I want sessions and I want them now.


The programmer wants to get on with creating the site not installing modules.


Perl programmers tend to be quite smart but forget that Perl has quite a learing curve. For some people the end product is all that matters and PHP makes it much easier.


Think of PHP as a consumer oriented programming language, like basic it is an attempt to make it easy for people with relatively little skill to achive things.


People used to snear at electical ignition on motorbikes that the japanese introduced as 'real bikers' kick started their bikes. Perl programmers tend to be like 'real bikers' bemoaning the PHP programmers for not being 'hard enough'.


Having said that I prefer to use Perl with Mason but then I have been programming for a very long time.

cowz
2004-08-19 08:09:12
Is it really a competition?
I don't think Perl needs to do anything. PHP 5 is first getting features that Perl has had for years. Perl is far more robust and complete, with a much better license and more flexibility.


My problem with this discussion comes in here: I see Perl and PHP having two totally different focuses. Perl is extremely good at system administration and real data processing, amongst many other things. PHP is extremely good at integration with web pages and databases, amongst many other things. When I want to build a full-featured program, I head toward Perl because that is what it was originally designed for and inherently best at. When I want to build a dynamic web site, I go to PHP because that is what it is designed for and inherently best at.


Yes, you can perform system administration with PHP and you can build good dynamic web content with Perl (thank to relatively flexible architectures and the insane desires of the developers for their language to be "THE END ALL") but the point is that it's simply not as easy. And programmers should be about easy, both for us and for end-users. That's why we're using computers (make complex math and communication easier) and why we don't write web pages using assembler or binary.


And yes, I do realize I've oversimplified. I can't wait to see the flames on this...

zero11
2004-08-19 11:22:11
it's the abstraction thing
personally i think PERL is the most beautiful of all languages. it's complexity, eloquence, and utility is not rivaled in any programming language. in how many other languages can you write the a program to do a task and have the begginer write it in 30 lines and the expert write it in 5 and yet still achieve identical results.


that said i've all but abandoned perl for web programming. not that it isn't rock solid, fast, and a joy to write, but because I have to work with HTML Developers and Designers. Designers and Developers need templates, they need to work in a world that is very literal and very visual. While perl provides tools to make this possible ( ePerl, HTML::Template and some others ) they lack the intuativeness and integration in to most WYSIWG tools that our visual brethern need, not to mention templating tools usually slow perl down dramatically. PHP is at it's core a web language and so it designed around the needs of Web Developers.


As for PHP5 I'm still very leary. PHP 4 was a complete pile of crap until well into 4.2 so I'm very iffy about upgrading. However it does fix some badly needed issues which have kept it from being used for serious developement. Namely PHP has finally implemented a standard and high performance XML and XSL parsers instead of the dodgey mess they were using. That with the addition of some very basic OO functionality have probably broadened the appeal of PHP to more advanced users who actually care about application design.


Lastly I've a comment to make on PHP CLI. STOP IT!!! Use Perl or Python or some language that is infinately more suited to this task. PHP is so behind these languages for regular app development it isn't even funny, and it still has a long way to go in web developement, best to focus on what you do well.

zero11
2004-08-19 13:03:15
Is it really a competition?
i don't think brian posed this as a competition, i think he is doing what alot of us should probably do more of. namely trying to imporove his community by looking at what has been effective for other communities. it's not "how can PERL be better than PHP", it's "how can PERL learn from PHP." what has made PHP so popular and is there something we can learn from in that?
elanthis
2004-08-19 20:55:58
Is it really a competition?
"When I want to build a full-featured program, I head toward Perl because that is what it was originally designed for and inherently best at."


As I recall, Perl was originally a better sed. Being an actual programming kind of just happened.


Which, lo and behold, is precisely what is (sort of) happening with PHP.


The advantages of CLI PHP are rather numerous, for some people. I use it a lot for web site utilities as it can use the support "libraries" I've written for the web sites themselves. Another huge advantage is that if you already know PHP, it's much easier to write an app in PHP than it is in Perl. PHP also has much easier to use OO facilities than Perl, which is important to some people.


And really, trying to make Perl good for everything is just going to make it suck everywhere. Use the right tool for the job. PHP is great for dynamic web site content. Perl is best for other tasks. Which is fine. There's nothing wrong with knowing or using multiple languages.

adrianh
2004-08-20 02:25:04
Ease of setup

What have we missed that the PHP folks clued-in on?


I'd go for ease of setup. It's really hard these days to find a W3 server that doesn't have PHP on. The same cannot be said for mod_perl + the templating module of your choice.


BuddhaJoe
2004-08-20 05:41:14
I think PHP is easier to pick up if you're a non-programmer
RTFM means nothing if you're not sure where the FM is or which part of the FM you need.


Amen!! :)


can I quote you?

LindsayLeeds
2004-08-20 10:13:47
Database Support
Well one reason I find PHP to be better is support for Microsoft SQL Server. There is no good free way to connect to SQL Server 2000 with Perl. PHP has ADODB which is IMO better than DBD/DBI. And it connects to MS SQL.
johnseq
2004-08-20 10:37:13
Database Support
Ways I connect to SQL Server from Perl


DBD::ODBC
DBD::ADO
DBD::FreeTDS


Two out of three will work from Unix.


shinichi
2004-08-20 11:23:00
what can perl do that php can't?
I have been a long time php programmer, and I like it so much. first because it's so easy, I started my first programming job not knowing php at all, but in 2 days I'm very productive already. Secondly, it's also powerful, I can do almost everything with just php, yes I wrote quite a lot of command line php for administrative task, and finds it sufficient for my need.


I have also done some perl programming (cgi, scripts to analyze log file, etc), although not so much. I would like to be as expert at perl as I'm in php. but one question that keeps coming is: what can perl do that php can't?
because everytime I think something might be better done in perl, I find it faster for me to just do it in php. So is there really something that php can't do that perl can do?


gavrosh
2004-08-20 14:06:32
perl vs php
I develop one of the biggest web sites in US, we do it with mod_perl and mason. When I ask someone that create web site with php how they solve specific problem he said me that he write apache module in "C".
You cannot compare perl vs php, it should be perl template system ( mason, template::toolkit, ... ) vs php, forget CGI, CGI id died.
I agree that it takes much more time to install perl template system than php, but it like to install linux or to go to computer store and to buy PC with preinstalled windows. If you will spend this "much more" time you'll get "much more" powerful system. More powerful tool cost more. It's like "Ford" for family needs and "Ferrari" for races.
php is more popular because most of web sites have simple functionality and their creators do not want ( and do not need ) to pay for something too powerful. php more popular than perl templates like "Ford" more popular than "Ferrari".
e_d
2004-08-20 14:37:49
documentation
Personally, I just program with php because of the documentation on php.net. I am not sure if it is as easy to look up perl functions (I dont play with perl unless I am writing a script for myself). But with php I can just go to php.net/whatever and find what I need easily without having to read through a bunch of junk that uses words I don't understand. php to me is also alot more forgiving when it comes to syntax, you can use ',", or nothing at all, variable types dont have to be declared, variables can be put within quotes. It just came easier to me naturally. Theres not alot of "Well before you can write your main code you have to do this, this, and this, and all this..."...It lets me get the good part of the coding quicker.
tima
2004-08-20 21:22:13
Ease of setup
+1
aristotle
2004-08-21 05:12:59
Brain-dead simple
I am talking from experience. I frequent a webdesign forum and have frequented several others over time. Where once upon a time there would be puzzled beginners trying to make CGIs full or pretzel logic work, they are nowadays asking how to get their equalled pretzelled PHP code to do what they want.


Judgemental as you may find that to sound, be aware that I know I too have written my pretzel logic CGI scripts, reinventing CGI.pm and a templating system with the rest of them. If I were a beginner now, I would most likely be doing that in PHP.


I hope you can draw your own conclusions from that.

Sunshine_Man
2004-08-22 07:03:36
i would choose perl
I've been working on Perl for commercial sites for the past 3 years. Before that, I've dabbled with ASP and Java. Recently, I did some PHP work as well.


I don't understand the argument that Perl modules are difficult to install; how does ppm in Windows make installing modules difficult? Or in FreeBSD, installing a Perl module is just like installing any other port.


My personal experience is that PHP is just too lax. What worked in my staging server seems to break so often in my customer's setup. Mind you, this is for a very simple dynamic page involving the barest of business logic.


With a single language that is Perl, I can code happily for all tasks: web pages, web services, administrative tasks, writing Windows services and daemons. The amount of available modules in the CPAN library is awesome, and I would like to take the opportunity to thank the good people out there who make their efforts available for all to use via CPAN.


I won't say that PHP is a poorer language, but I will like to say that there's a lot of strengths in Perl that does not seem to be experienced by the commentors so far. To those who say that Perl is more difficult to learn than PHP, I will only reply that PHP is modeled after Perl. In fact, many people often say that that if you know PHP, you know Perl. Well, almost!

Offer Kaye
2004-08-23 00:56:37
documentation
I am not sure if it is as easy to look up perl functions... But with php I can just go to php.net/whatever and find what I need easily without having to read through a bunch of junk that uses words I don't understand

Actually, it is very easy to lookup Perl documentation- you can either use the command line (e.g. "perldoc -f function" to lookup a function, or "perldoc Module" to lookup a module), or, if you prefer to lookup stuff on a website, use http://www.perldoc.com/. As for the "junk" part, I'd like to hear which part exactly you consider "junk" or using "words you don't understand".

You go on to say that you prefer PHP since it "is also alot more forgiving when it comes to syntax". Well, bully for you. All of the points you raise are just as true (if not more so) for Perl, in fact for some people Perl's syntax is too forgiving.

Finally, you claim you have to do a lot of stuff in Perl before getting to actually coding. What exactly are these preparations? Funny, I've never encountered them...

Brian asked which things PHP gets right that Perl doesn't. If you're going to reply, at least have some minimum knowledge of Perl before trashing it as a language...



Offer Kaye
DWC
2004-08-23 02:19:11
Who is playing catch-up...?
The entire game is about capturing the user base. The merits, strengths and weaknesses are secondary.
Consider the way that Microsoft took over the world with Windows... Or how VHS ousted [sp?] Betamax...
PHP catered to (created) a community that was enthusiastic, but not necessarily technical (to start with). Loads of people had ideas about doing 'something' on or with the internet, but they couldn't get to grips with Perl. Some one showed them that all they needed was a bit of HTML and some PHP. (I really believe that PHP came about as an open source response to ASP).
Even Linux struggled(s) from this issue: Linux started as an exclusive - geek - community, and that is probably how Perl was(is) perceived.
Technically, PHP CLI is a response to calls from the PHP community who want more Perl-like utils and features.


What can be learned from PHP? Development, Marketing, Promotion, Collaboration (ala LAMP), Education (how many newbies know about CPAN?), Documentation, Tutorials (yes, more of them)... all in the same place - on a web site! not via CLI


Are you bothered that PHP is more popular then Perl, when Perl is 'better' than PHP? Only you know the answer to that!

TimmMurray
2004-08-23 06:25:07
what can perl do that php can't?

So is there really something that php can't do that perl can do?


Nothing. General-purpose programming languages never differ in what they can do (Google for "Turing Complete" and "Turing Tarpit"). They differ in what they make easy.

scottlc
2004-08-25 10:46:22
documentation
php to me is also alot more forgiving when it comes to syntax, you can use ',", or nothing at all, variable types dont have to be declared, variables can be put within quotes.


Actually, Perl does allow you to use different quote charactors: '' for non-interpolated quotes, "" for interpolated quotes etc... In Perl, variable types can be declared, which is a good idea to get used to, but you can choose not to declare them if you want. Perl allows you to put variables into double-quoted (interpolated) strings.

scottlc
2004-08-25 11:37:15
Non-perl folks think that Perl is slow
First of all, I'd like to state that I am a self-taught programmer, and a big fan of Perl. There have been many good points raised, it would be pointless for me to reiterate all of them, but there is one main misconception surrounding Perl that I have certainly found.


Something that has certainly cropped up for me, and for others I'm sure, is the age old impression that the only way for Perl to interface with your web server is via CGI. But with mod_perl, PerlIS, FastCGI Perl and SpeedyCGI we have infinitly better, faster and much less resource hungry ways to interface. But the misconception that Perl is a CGI dinosaur is still there, which damages Perl's image.


Secondly, mod_perl + Mason give a similar style of coding to PHP, but with the raw power of Perl. A prospect that excites me; if only shared hosting companies would adopt it.


I however can see the advantages of PHP. It is much easier to pickup, but that has it's disadvantages. I have seen much insecure, sloppy and altogether terrable PHP code. And while I don't use PHP myself, I did decide to try it out not long ago, and found it to be rather easy to pick up. This obviously brings disadvantages, as important security concerns may be more easily overlooked.

JMW
2004-09-13 10:41:15
Well, good thing I saw this thread!
Now, today I start my journey into the PHP world as I was undecided. It seems perl is taking a beating all over the web forums is all I can see, dr.


Huge percent of programmers agree PHP is better for the web and perl for building applications is all I've seen.


There you got your answer doc. Perl's a.. has been whuuped and then again for not getting out of the corner.


I'll drop by Larry Ullman's site.

Vernon_T_Bludgeon
2004-10-01 07:50:28
it's the abstraction thing
personally i think PERL is the most beautiful of all languages. it's complexity, eloquence, and utility is not rivaled in any programming language.


Huh? I thought Larry Wall himself has said, essentially, that Perl smells like a camel.

fams
2004-10-18 10:39:20
documentation
correct, the perldoc is great. But the php.net documentation is ALIVE, you can post coments, questions, answers, EXAMPLES.
Everithing in a same place.
webshowpro
2004-10-20 21:35:41
it's the abstraction thing
Lastly I've a comment to make on PHP CLI. STOP IT!!! Use Perl or Python or some language that is infinately more suited to this task. PHP is so behind these languages for regular app development it isn't even funny, and it still has a long way to go in web developement, best to focus on what you do well.


Huh? PHP is great for the command line, it allows me to share a single set of library scripts so that building web front-ends to systems tasks is almost trivial.


Why should I have another set of scripts, to connect to a database and lookup values? I did use PERL for a long time, because it was "right". It cause countless headaches, because if a schema changed, or the web front end changed, the backend code all had to be updated tested. Now if it work on the web end, I know it works on the system side too. It has saved me countless hours.


NetWielder
2005-01-13 04:17:47
Simplicity vs. Flexibility
I am both proficient and experienced in both languages. IMHO Perl offers flexibility e.g., more than one way to do it ;-) and PHP offers simplicty. I am patiently awaiting Perl 6 (and parrot) to see when and how the Perl language developers will be able to address the desired PHP features and language constructs.
qJustQ
2005-05-02 21:54:54
Perl extension for PHP5
// example 1

print "Hello from PHP!\n";
$perl = new Perl();
$perl->eval('print "Hello from Perl!\n"');
print "Bye!\n";


?>


// example 2

$perl = new Perl();
$perl->eval('
sub sum {
my $x = shift(@_);
foreach my $y (@_) {
$x += $y;
}
return $x;
}
');


print $perl->eval("sum(1, 2, 3, 4, 5, 6, 7, 8, 9)")."\n";
print $perl->sum(1, 2, 3, 4, 5, 6, 7, 8, 9)."\n";


?>

hackerjosh
2005-08-09 21:34:00
i would choose perl
In fact, many people often say that that if you know PHP, you know Perl. Well, almost!

I experienced this backwards. I started with Perl and started messing with PHP when I was working on a website done with PHP. I found PHP was very easy to use. Basically all I needed was the manual to look up function names. I guess what impressed me most about PHP was all of the built-in functions. It has most everything you need and you don't have to make trips to CPAN to get them.


And now I'm trying to decide which language to use for a web application I'll be developing.

Eclectic
2006-01-13 08:11:06
Who is playing catch-up...?
Right on the nose. Never underestimate the power of market timing. PHP filled a need (ASP style programming for the rest of us) that Perl simply ignored at the time. Plus Perl is so linked up with CGI in peoples minds that it was bound to share the same fate.
Perl, IMO, is leaps and bounds above PHP in expressive power (nested eval, exec, grep), to the point of being dangerous even. PHP however, shines in the area it was designed for, web development.
I always wonder why command line lovers scoff at visual development - is anyone actually reading this web page using Lynx?
shinklee
2006-01-25 14:49:41
He is asking for directions.
My background.
Masters in Comp Sci
Experience in high and low level languages.
From Assembly to C++ to JAVA to shell programming.


In the commercial world it is good to know both Perl and PHP.


If your job requires you to develope a UNIX Web Server that requires both text processing applications and dynamic web pages you want a language that is extensive and quick or two languages that can complement.


PERL is extensive for application building.
PHP is quick.


Would you rather learn JAVA and C++...?
These are powerful over kill languages for most tasks. Difficult to learn for most people.


PHP and Perl combined can handle UNIX admin and WEB services.


Learn both if you can.


Erick Willemse
2006-06-06 21:48:23
Great website! Bookmarked! I am impressed at your work!
iain duncan
2006-06-13 11:13:37
Personally, when I have a choice, I use Python. But when I am trying to get something to work on a web app that I haven't done before, finding out how is easier with PHP then with anything else. The documentation on php.net is fantastic and the builtins are extensive. I expect it is a perfect example of how the overlooked aspects (docs, main website ) can make a massive difference to the number of adopters in the long run.