Perl vs PHP

Discussion in 'Web Design and Development (archive)' started by tomf87, Feb 19, 2004.

  1. macrumors 65816

    tomf87

    Joined:
    Sep 10, 2003
    #1
    I've just started reading "Learning Perl, 3rd Edition" recently, mainly because I can do system scripts and some web pages with it.

    I started reading about PHP today as well, and I'm curious to know what your experience with each language has been. Is there a certain time you would use one over the other? Is there certain capabilities in each language?
     
  2. Moderator emeritus

    Rower_CPU

    Joined:
    Oct 5, 2001
    Location:
    San Diego, CA
    #2
    I'm a PHP developer with absolutely zero Perl experience, so I'm curious about the differences between the two, too.
     
  3. macrumors 601

    Westside guy

    Joined:
    Oct 15, 2003
    Location:
    The soggy part of the Pacific NW
    #3
    I know perl better than php, so understand that I'm biased here.

    Perl is a more mature language, and is significantly less vulnerable to exploits. It's more powerful as well. BUT it is harder to learn for sure. php makes scripting on Unix pretty much like writing ASP pages for a Microsoft server. But the bottom line is you can do stuff with perl that you can't with php - the converse isn't true.

    I'm responsible for a Webserver that perhaps a hundred people have write access to, and everyone in the department (maybe 1000 people) can at least log in. Since the skill level of our users varies quite a bit, we limit what they're allowed to do. On our server we have php disabled simply because it's less mature and therefore more exploitable. php exploits still come out every month or two, and they tend to be "severe" bugs. BTW we don't allow unrestricted CGI access either; I have to vet most scripts before they're made live (except for a few users whose skill levels are good).

    Edit: I should probably point out that in many production environments you can set all scripts to run under the specific user's permissions - so at worst they can only compromise they're own files. But in our particular setup that's not practical (except for a few virtual hosts that are on our system - in those cases we do that).
     
  4. Moderator emeritus

    Rower_CPU

    Joined:
    Oct 5, 2001
    Location:
    San Diego, CA
    #4
    Interesting points, Westside Guy...

    A couple questions:
    Isn't PHP designed explicitly for web dev, whereas Perl is scripting applied to web dev?
    Also, how does database access work with Perl?
     
  5. macrumors 6502a

    ExoticFish

    Joined:
    Dec 3, 2002
    Location:
    The inner depths of madness, aka Kent, OH
    #5
    i write perl but know little php. perl is a language that is used for most anything and everything while php seems to be used for mainly web stuff although it can be used as a laguage like perl as well... it's just that no one does. if this post doesn't make sense it's because i'm half asleep.
     
  6. macrumors 601

    Westside guy

    Joined:
    Oct 15, 2003
    Location:
    The soggy part of the Pacific NW
    #6
    1) I believe you're right, although I don't know about PHP's origins. Perl pre-dates the Web. It's just such a useful scripting language that a lot of modules have sprung up specifically for Web work (such as cgi.pm).

    2) For SQL access the standard module is DBI. It works quite well - I've used it a lot of late.

    A lot of people who do SQL work rave about another language called Python. It apparently has a really well-thought-out database interface.

    Actually looking at my previous post, I guess I sounded anti-PHP. I don't mean to be - it's just for our particular situation I don't think PHP is a good fit. Personally I'd like to learn it better; mainly to pad my resume. :D
     
  7. macrumors 601

    Westside guy

    Joined:
    Oct 15, 2003
    Location:
    The soggy part of the Pacific NW
    #7
    This might interest folks - just found it. Looks like PHP and Perl are cousins.

    The history of PHP
     
  8. thread starter macrumors 65816

    tomf87

    Joined:
    Sep 10, 2003
    #8
    I used to work for a company that hosted sites that used only Perl. They had custom Perl functions that used DBI to connect to Oracle7 and Oracle8 and it ran fine.

    I just don't know if by reading up on Perl, I'm missing something on PHP, or Python as Westside pointed out.
     
  9. macrumors 603

    jeremy.king

    Joined:
    Jul 23, 2002
    Location:
    Fuquay Varina, NC
    #9
    I think its funny that PHP is capitalized, even though it no longer stands for "Personal Home Page" and Perl is mixed case, while it still stands for "Practical Extraction and Report Language"

    PHP is far easier to use and learn, but Perl will give you more flexibility and power. mod_perl will give you the best performance, while PHP is fairly straightforward to code and has a huge function library built in.
     
  10. macrumors 65816

    D0ct0rteeth

    Joined:
    Mar 11, 2002
    Location:
    Franklin, TN
    #10
    Westside Guy knows his stuff.

    Yeah.. I use PHP and Perl hand in hand on almost every project.. PHP wandles all the routine web stuff while Perl does the heavy lifting.

    Both are valuable tools, and whenever I have to play with another language XML builds a nice bridge.

    I cant say learn one over the other but the best summary is what WG said "Perl is a more mature language, and is significantly less vulnerable to exploits. It's more powerful as well. BUT it is harder to learn for sure. php makes scripting on Unix pretty much like writing ASP pages for a Microsoft server. But the bottom line is you can do stuff with perl that you can't with php - the converse isn't true."

    - Doc
     
  11. thread starter macrumors 65816

    tomf87

    Joined:
    Sep 10, 2003
    #11
    Evidentally, there's a reason for that. According to my book, it says:

    "It's actually a retronym, not an acronym. That is, Larry came up with the name first, and the expansion later. That's why "Perl" isn't in all caps." Learning Perl, 3rd Edition, page 4

    I had never heard of a retronym until now.. :)
     
  12. macrumors regular

    Joined:
    Aug 28, 2003
    Location:
    NJ, USA
    #12
    'News' is supposed to be a retronym (not widely used or accepted, of course ) : North, East, West, South.


    back to the thread : Perl has given birth to various other languages, the more prevalent today being PHP, Python and Ruby. Of these, PHP is the most interesting one. Not nearly as good as Perl, but its fun to work in.

    Python could have been good, but they have many weird practices, like 'white spaces have significance in the code' (like COBOL) or some such garbage.

    Ruby's raison raison d aitre seems to be the older Perl's not-so-good (supposedly) OO handling. But with the latest versions I am guessing that does not hold water much.

    Gist : if you want a really powerful language, nothing beats Perl. If you still want to have an alternative fun thing to look at, check out PHP.
     
  13. macrumors 601

    Westside guy

    Joined:
    Oct 15, 2003
    Location:
    The soggy part of the Pacific NW
    #13
    mod_php question

    Could anyone point me towards the mod_php documentation? I searched apache.org, php.net, and did a quick google search; but I didn't find anything that was at all thorough.

    What I'd like to find out is what limitations and/or control statements it recognizes, if I actually were to enable it on an Apache server. I've got a testbed box I can use to try things out on - comes in handy on occasion.
     
  14. thread starter macrumors 65816

    tomf87

    Joined:
    Sep 10, 2003
    #14
    I can't find the mod_php docs anywhere. Isn't mod_php just a module for Apache that let's you run PHP code inside the web server? If so, wouldn't the PHP docs work?

    I guess the same question would go for Perl as well. What's the difference between Perl and mod_perl?
     
  15. macrumors 601

    Westside guy

    Joined:
    Oct 15, 2003
    Location:
    The soggy part of the Pacific NW
    #15
    I guess I didn't phrase my question well; sorry.

    Most modules that can be run with Apache will have some set of parameters that can be set to control how it runs. You might be able to control which directories they're enabled in, for instance - in that case if you support a lot of users, and want to test their knowledge before giving them access to that particular tool, you could do it. Or perhaps you could enable only a subset of the functionality, etc.

    But it all would depend on what options the person(s) who build the module decided to leave accessible. So with mod_php, perhaps there are no options - you can only turn it on or off, in other words. Or perhaps there are tons of customizable options available. Without the documentation it's hard to know.

    Mod_perl has tons of on-line documentation. I'm looking for the same sort of information about mod_php.
     
  16. macrumors member

    Joined:
    Jan 12, 2004
    Location:
    Minnesota
    #16
    It stands for PHP: Hypertext Preprocessor now. It's a recursive acronym.
     
  17. macrumors 65816

    mrjamin

    Joined:
    Feb 6, 2003
    Location:
    Strongbadia
    #17
    thats arguable - the significance of whitespace and indentation forces good programming practice - it makes your code much easier to revisit, and for others to look at. Many people have different coding styles when it comes to indentation and whitespace etc which can make it difficult to read other peoples' work. In python, non-standard whitespace usage and indentation solves this

    Many of my friends started on perl, explored PHP, then ditched both in favour of Python - i'm toying with doing the same.

    I still stick with PHP for webdev stuff, and the odd bit of non-webdev stuff as you can execute PHP scripts in the same way you would a perl script. While I appreciate the benefits of perl, i still prefer PHP for most of the work I do. Also, in my experience, PHP scripts tend to execute significantly faster than most perl scripts.

    edit: FWIW python is much better than PHP as far as OO (object orientated) coding is concerned. Its XML parsing is also miles ahead of perl 5 and PHP. Having said that, PHP5 and Perl 6 are supposed to "meet the bar" on both areas once they're released (infact, wasn't perl 6 finalised earlier this week?)
     
  18. Moderator emeritus

    Joined:
    Jun 25, 2002
    Location:
    Gone but not forgotten.
    #18
    Python is good because it forces indentation. If you've had to port 100,000 poorly-written, undocumented C code, I would think that you would instantly realise the benefit of being able to read strictly structured code.

    On the other hand, COBOL's Area-A, Area-B are more arbitrary but force categorisation--DIVISION vs. its subordinates SECTIONs. It was mainly used to aid the compiler in quickly identifying problems with the code. If you think that's bad, take a look at RPG II or RPG/III. :D

    Perl always seemed odd to me but I have found the familiarity of PHP's syntax to be comforting.
     
  19. Moderator

    Nermal

    Staff Member

    Joined:
    Dec 7, 2002
    Location:
    Whakatane, New Zealand
    #19
    Interesting, I'm learning PHP this year (haven't started yet). I have some ASP.net experience, but I don't really like it because it's so Windows-centric. It'll be good to learn something open like PHP :)

    We're also using MySQL. Something I don't understand though is that we're using MySQL for our Web App Development class, but for our Windows Programming class, taught by the same teacher, we're using Firebird :rolleyes:
     
  20. Moderator

    Nermal

    Staff Member

    Joined:
    Dec 7, 2002
    Location:
    Whakatane, New Zealand
    #20
    Mouse Activated Computer-intosh :)
     
  21. macrumors regular

    Joined:
    Nov 13, 2003
    #21
    I *********love********** MySQL :D
     
  22. Moderator

    Nermal

    Staff Member

    Joined:
    Dec 7, 2002
    Location:
    Whakatane, New Zealand
    #22
    Well I haven't had any experience with it yet, but I will have by the end of the course. Our teacher is one of the Firebird developers, so he told us all about the Firebird/Firefox fight :D
     
  23. Moderator emeritus

    Joined:
    Jun 25, 2002
    Location:
    Gone but not forgotten.
    #23
    Firebird is based on Borland's InterBase, which was quite a good database engine. I'm happy to see that there is even a Mac OS X version.

    I was quite surprised to find that the thing was originally written in C. The Firebird team is re-working it for C++, so it should be more flexible. Then again, the Borland Database Engine only had C bindings...
     
  24. macrumors 6502

    Joined:
    Sep 4, 2001
    Location:
    West Sussex, UK
    #24
    I just wish MySQL had support for nested queries. I know it is coming in version 4.1 but it should have been there long ago. I often find times where I would like to use a subquerie and MySQL just can't do it so I have to code around it. Not difficult but incredibly annoying.

    I also remember reading that transactions were not supported until MySQL 4. I'm not sure if that is correct or not but it may be.

    Another thing I remember reading was that MySQL does not enforce referential integrity on foreign keys. Again I'm not sure if its true (and it doesn't really bother me) but surely this is something it should do.
     
  25. macrumors 601

    Westside guy

    Joined:
    Oct 15, 2003
    Location:
    The soggy part of the Pacific NW
    #25
    I think that's why Red Hat and others went to postgresql - mysql is in some ways rather immature (although it's great for what I need to do).
     

Share This Page