Forum Moderators: coopster & phranque

Message Too Old, No Replies

Perl or PHP?

         

kapow

3:09 pm on Jul 27, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



My life story so far:
I started out life as a Graphic Designer needing to learn website development. After html I learned that server side scripting is necessary for the clever stuff so:
I bought a big book on Java (because I had heard of it somewhere), began reading it ZZZzzzzz...
Then I heard that ASP was more popular, bought a big ASP book, began reading it ZZZzzzzz... I then found that the host I use (Pair.com) support PHP not ASP. So, guess what? bought a big PHP book, began reading it ZZZzzzzz... I have had some good results with PHP (for a beginner).
Now:
Having read a lot at WMW and been asked to create an InTRAnet site I am wondering if I should learn Pearl. Before I rush out and buy that fat book, is there an expert at perl/cgi (sorry I don't know the difference) who can advise if this is more generally useful than PHP ie more likley to run on other servers?

ps: Anybody interested in my second-hand book store :)

Eric_Jarvis

3:18 pm on Jul 27, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



PERL is pretty much available all over the place...it's also very robust...I found it pretty easy to get started with and so haven't bothered with PHP, ASP so far

john316

3:27 pm on Jul 27, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The difference that I have seen is that there are a plethora of "ready to run" PERL scripts available for just about any purpose, many are free and others are well worth the small investment when considering YOUR time. There are a lot of PHP resources available, but my experience has been that they are not nearly as easily customized as PERL scripts.

ggrot

3:44 pm on Jul 27, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, my original background is in programming languages and I do alot for the web. I started writing scripts in C...lol. But I digree.

PHP's language is based largely on PERL with a bit of object oriented from C++ thrown in for good measure. If you already know PHP, you understand the PERL syntaxes already. PHP was designed to replace PERL. For web based use, it has all the same functionality plus alot of stuff. For example, PERL does not allow for the functional equivalent of
include("morestuff.html"); or inline html code.

Thats a big thing for making sites that can update the design by changing one file. Also, for stuff like reading a remote file, PHP is seamless, PERL requires opening a socket and doing all the underlying work by hand. Same with email...PERL requires accessing the command line(security risk) and knowing how to interface with sendmail(learning curve). If you know php...thats the way to go. It can't hurt to look at perl either, it will make porting premade stuff far easier.

john316

3:59 pm on Jul 27, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The difference that I have seen is that there are a plethora of "ready to run" PERL scripts available for just about any purpose, many are free and others are well worth the small investment when considering YOUR time. There are a lot of PHP resources available, but my experience has been that they are not nearly as easily customized as PERL scripts.

alexjc

4:26 pm on Jul 27, 2001 (gmt 0)

10+ Year Member



I've got a fair bit of experience with both PHP and Perl... and i find they cancel out each other's disadvantages. My next site (i.e. first big ambicious site ;)) is featuring both.

<b>Perl</b>

+ great support
+ faster
+ eleguant if you spend enough time trying to understand it
+ CGI / web tech is only a small part of what it can do

- tedious to integrate html into (templates are a good option, but slower to parse)
- and conversely, not so easy to integrate into html (SSI)

<b>PHP</b>

+ very simple cookie, post/get variable handling
+ designed, and very well suited to web apps
+ easy to integrate into html (designed that way)

- not as powerfull as perl
- slower
- print syntax frustratingly tedious... try: print "<b> $msg['title'] </b>"
it won't work!
- support not as good

So what i've ended up with, which i think is a good compromise: Perl does all the processing, and PHP i use as a dynamic template (how much is does depends on how often the page is hit, but i keep it to a minimum). Perl scripts sit in between form posts, and php templates... apache's internal redirect (mod_perl) is used at it's best here :P

That works ok for me, but i have had to get used to both the languages. Admitedly, they are <i>very</i> similar, but some features are much different.

Just my 2p.

Alex

ggrot

4:47 pm on Jul 27, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



PHP should be faster in general for web server uses. It runs as an apache module as opposed to a external compiler. PHP gets parsed, whereas PERL gets compiled <i>every</i> time then gets run.

But i do like the idea of using perl+php. You can also include(""); the perl output into a php document. PERL is a little more robust in string manipulation. It would be nice to see better 'magic quotes' in PHP for later releases.

alexjc

5:02 pm on Jul 27, 2001 (gmt 0)

10+ Year Member



> whereas PERL gets compiled <i>every</i> time

With mod_perl, the script is compiled on first use... the compiled version is then used when necessary. The perl program also sits constantly in memory, so there is no overhead for loading and unloading it.

littleman

5:08 pm on Jul 27, 2001 (gmt 0)



Speed - It depends on how perl is run - mod_perl comes out ahead of mod_php in benchmark tests.

circuitjump

5:49 pm on Jul 27, 2001 (gmt 0)

10+ Year Member



>> - print syntax frustratingly tedious... try: print "<b> $msg['title'] </b>" <<

Alexjc, I think it won't work unless you try it this way:

print "<b>".$msg[title]."</b>";

Since it's an array variable, at least thats what it looks like, you need to add a dot to tell it it's gonna print out a variable along with the html.

Just trying to help :)

David

7:27 pm on Jul 27, 2001 (gmt 0)

10+ Year Member



Its a good question and one I was about to post. I have spent the last 6 weeks learning PHP and continue to be amazed with its flexibility.

I think I have convinced myself that learning at least the basics of perl are important if you are going to be working with several different web-sites. Then at least you can install and trouble shoot ready to go scripts.

It also seems to me that if you have a good understanding of both PHP and ASP(Haven't looked at ASP yet)you should be able to accomplish just about any server side scripting web wide. Am I wrong?

As for embeding the variable in the html I would escape to PHP mode like this.

<b><? $msg['title']; ?></b>

circuitjump

7:52 pm on Jul 27, 2001 (gmt 0)

10+ Year Member



Good one.

Never thought of doing it that way.

David

9:19 pm on Jul 27, 2001 (gmt 0)

10+ Year Member



oops..

should be

<b><? echo $msg['title']; ?></b>

alexjc

6:11 pm on Jul 28, 2001 (gmt 0)

10+ Year Member



There's an even quicker shorthand notation you can use if you want to print the variable:

<?= $msg['title'] ?>

But my problem was from within a SQL query, so I had to concat the strings together with '.'. It's a bit tedious when you're used to perl being able to handle...

print "$msg{'title'}";

without any trouble.

Bolotomus

7:07 pm on Jul 28, 2001 (gmt 0)

10+ Year Member



Gentlemen... Alexjc was almost correct, you CAN do this in Pearl... er, Perl...

print "<b> $msg['title'] </b>"

Except for one thing, $msg['title'] doesn't make much sense, I think he meant $msg{'title'} assuming msg is a hash %msg and not an array @msg. Therefore, try this:

print "<b> $msg{'title'} </b>"

You can even skip the single-quotes, e.g.

print "<b> $msg{title} </b>"

Perl is like a good listener. If you say something that can only be interpreted one way (like leaving the single-quotes off of a hash key) then Perl will assume you meant the only thing you possibly could of meant.

Perl is a lot of like natural language, inasmuch as a programming language can be. For example, the construct $_ is a lot like the English word "it."

I am not going to say anything bad about PHP--I don't know enough PHP to criticize it. But I will tell you, I love Perl.

Here's a viable third choice: e-perl.

BOLOT

alexjc

5:09 pm on Jul 29, 2001 (gmt 0)

10+ Year Member



> print "<b> $msg['title'] </b>"
> Except for one thing, $msg['title'] doesn't make much sense

hehe, that was the PHP ;)

> You can even skip the single-quotes, e.g.
> print "<b> $msg{title} </b>"

But i think that's depreciated... it's been a while since I read the manual!

stickytape

12:48 pm on Aug 1, 2001 (gmt 0)



Well, here's my 2p:

Im just starting out life as a web designer. Im only 20, so quite young and have relatively little experience. I havent worked on anything big yet, but have done quite a lot of web sites - for my Dad, for my local cricket club etc etc. I too was puzzled with what language to learn after I picked up HTML. I decided PHP, mainly because it appeared to be more like plain English than Perl. I also managed to find some good articles about PHP and Databases [webmasterbase.com] which I enjoyed. I've only been learning for about 3 weeks now, and I must say I am happy I chose PHP. Mainly because I seem to have picked up the basics quickly, and have enjoyed it. PHP is definately a growing language and I think that it will expand in years to come.

I have briefly looked at Perl in the past, and I didnt really enjoy it. It appeared to be a chore to learn it. However, PHP has been fun - so to speak.

Well, that's my side of the coin. Good luck on your voyage.

Sticky

Brett_Tabke

1:09 pm on Aug 1, 2001 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



my .02.

If you have time to learn, skip the scripting languages and learn C.

caine

1:56 pm on Aug 1, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Brett,

Though, i heard only good things about C, i thought it was a particarly hard language to learn. Furthermore, can C do what Perl / PHP can do in all there possible environmental contexts.

As i am at the doorway of beginning to learn perl, and in october learning Java, what would you say about C ?

Any books you recommend ?

Caine

sugarkane

5:55 pm on Aug 1, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> can C do what Perl / PHP can do

As Perl and PHP are written in C (or C++ whatever), C can do everything they can do... eventually... your code will be ten times as long and ten times as complex though ;)

Brett, didn't you know that real hombres / hombrets [webmasterworld.com] do CGI stuff in assembler?

ggrot

7:15 pm on Aug 1, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I hate to sound like I'm getting into a 'my language is better' argument, but PHP (and Perl) really are better and quicker for most small - medium size web development projects.

I use C++ all the time for other things, and for large web dev projects or things that arent UI intensive(massive data mining for example), its perfect. It is faster, more scalable, more powerful, etc but yet its string manipulation, standard socket protocol support, etc, are lacking for the web. If you go build some custom libraries to fix this, great, but thats overhead

theperlyking

7:50 pm on Aug 1, 2001 (gmt 0)

10+ Year Member



Sometimes theres no point reinventing the wheel and thats where the diversity of programming languages come in, sure you can code in C and it will be fast and small, but you can potentially get to your goal much quicker using the help that a higher level language such as perl can give.

alexjc

11:20 pm on Aug 1, 2001 (gmt 0)

10+ Year Member



My advice is NOT to learn C just for CGI scripting. It's not worth the hassle. C is fairly difficult to learn, and the benefits aren't that great. The only thing you'll get is a bit of extra speed.

Perl is the way to go for scripting. Easier to learn too... All the string , hash table functions are optimised to bits, and you'll do very well to get a C program runing as fast. You'll have to put in some time, and you'll need the experience.

I've been doing C for about 4 years now, low level computer graphics. And despite that, I learnt Perl specially for web design, and not regretting it. PHP is a small subset (tweaked) of Perl, so if you learn the latter, the former will follow!

Admitedly, I would use C for any complex web algorithm that I would have to code. But not for common stuff (forum, error handling, link checking, spidering, log analysis).

My 2p.

Alex

Brett_Tabke

11:39 am on Aug 2, 2001 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



> real hombres / hombrets do CGI stuff in assembler?

Absolutely! I've said it for years. Start with this premise: all languages other than the processors native language are crap. The only question in deciding which language to learn is, do you want to be standing in sess up to your waste, or sess up to your neck?

If you are learning a language that you want to program in for the rest of your life and be able to program groovy gui apps for your OS - C is the way to go. If you want to program in a language specifically for cgi - Perl is the way to go. It's by far the easist language I've learned since Basic. If you are on a iis server with basic available, I might even be tempted to go that route. There aren't enough Basic cgi's out there and I don't see any reason for it. It is as fast as perl (faster in some cases), and just as flexible. I've always thought of Perl as a brother to Basic anyway.

Bolotomus

9:39 pm on Aug 2, 2001 (gmt 0)

10+ Year Member



Perl often is labeled an "interpreted language" (which is only half correct) and therefore lumped in with BASIC and other interpreted languages. Perl is not known for its speed. But I say, take a closer look...

C and C++ are considered more low-level, and much faster compiled languages. After all, Perl is written in C, so how can Perl be faster than C?

Oddly, Perl can be faster than C in real-world applications. Why? Because C, for all its strengths, does have many weaknesses which Perl set out to correct. The biggest weakness is the handling of strings (text). Perl processes text with incredible ease, not just from the programmer's standpoint but from the internal standpoint as well (the garbage collection, linking, etc.). In the end, lots of Perl programs that do heavy text-processing run faster than unsophisticated C counterparts--or even assembler counterparts--that attempt the same thing. (I say "unsophisticated" because obviously some assembler or C programs are written to be as good or better than Perl, even in the text-processing arena. But you'd find that in writing such a program you'd end up reinventing a lot of the algorithms already built into Perl.)

alexjc

3:33 pm on Aug 3, 2001 (gmt 0)

10+ Year Member



A compiled version of each script can be used if you use mod_perl, so look into that if you're desperate for every clock cycle you can get!

Bolotomus

8:01 pm on Aug 3, 2001 (gmt 0)

10+ Year Member



We could start a whole other threat "Is Perl compiled or interpreted?" The answer is not clear-cut and there are whole web sites that try to explain the issue. Even the 'compiled' code you talk about is not compiled as C is compiled; there are no machine-level instructions produced by the Perl compiler.

However, agreed, mod_perl is great. Wouldn't do anything for production purposes without it.