ps: Anybody interested in my second-hand book store :)
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.
<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
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, 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 :)
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>
<?= $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.
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
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
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
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?
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
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
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.
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.)
However, agreed, mod_perl is great. Wouldn't do anything for production purposes without it.