Jump to content

Archived

This topic is now archived and is closed to further replies.

.josh

is Perl worth it?

Recommended Posts

okay i've looked into Perl in the past. I learned the hello world program and that's about it.  So I really don't know anything about Perl.  So out of curiosity or boredom or both, I decided to ask if Perl is worth learning if i'm already on the PHP path? I would never give up PHP! But Is there something that Perl does that you can't really do with PHP? Does it just boil down to a matter of preference/beefing up your general server side scripting knowledge, in case a site was done in Perl?

Share this post


Link to post
Share on other sites
eh... with the little bit of Perl work I've done, it's waaay better at handling text manipulation, but other than that, PHP can handle a lot.

Perl is a nice tool to have in your box, but not a necessity.

Share this post


Link to post
Share on other sites
[quote]But Is there something that Perl does that you can't really do with PHP?[/quote]

Yes. [url=http://tnx.nl/php]This[/url] may be helpful. (The image was causing a slow load time for me, so stop the document manually if need be.)

I've been doing Perl for about a year and a half now, and suprisingly enough, I haven't used it for the web yet. Although my command line usage of PHP has been minimal, I think Perl has the upper hand here.

I see PHP as a language that has a lot to offer in terms of broad, high-level libraries. Perl offers this as well via [url=http://cpan.org/]CPAN[/url], which is an awesome resource. I guess this would be the equivalence of PHP's PEAR, which I am not familiar with.

I see Perl as a down-and-dirty language. It offers advanced regular expressions which are built into the syntax of the language, flexible data structures, symbol table manipulations, namespaces, etc.

I would say that the implementation of OPP in PHP is better than Perl. Perl uses a lot of reference trickery, and although it works well, it's not always "official." (For giggles, Perl's OPP is known as POOP.)

Perl also offers [url=http://www.oreilly.com/catalog/perltestingadn/]testing[/url] (I don't know if PHP does). In Perl, you could write a series of tests, team them up with a [url=http://search.cpan.org/~petdance/WWW-Mechanize-1.20/lib/WWW/Mechanize.pm]browsing object[/url], and it would run through your entire site and tell you what broke. I have yet to venture into this aspect; I'm still learning a lot elsewhere.

If you're digging through data or writing a lot of system tools, Perl is the way to go. If you're creating templates and working with a database... I can't say--I'm not familiar with Perl's web tools.

Personally, I still like PHP because it's where I first started and I have more experience and existing code to maintain. Once I find time to dig into Perl's web capabilities, things may change. I really appreciate Perl's short-cuts, clever syntax implementations, context handling, and control. They have an awesome community as well.

Working with PHP taught me a lot about the workings of the web; working with Perl taught me a lot about programming.

Share this post


Link to post
Share on other sites
I am a self-taught Perl guy, so I can't really speak to PHP's advantages/disadvantages, other than what I've seen here in the forums. 

First, I tend to like namespaces, and I don't see PHP with those. 
Second, PHP was designed to be "embedded" in HTML, and I don't like that either. 
Third, PHP has far too many different functions to match strings, which all take parameters in random order. 
Fourth, I couldn't live without hashrefs for everything, and I don't see that as native in PHP, though I might have missed it.
Fifth, Perl has been around for decades, isn't going anywhere, and CPAN is the best resource on the planet, if you don't feel like "rolling-your-own", which is what we Perl ppl do best anyway.

The list goes on and on... I couldn't ever abandon Perl.  Feel free to correct me if need be.

Share this post


Link to post
Share on other sites
i'd like to try and clear something up here. plenty of recent posts say along the lines of "i looked at xxxxx language. Is there anything that xxxxx can do that yyyyy can't do?"

would it be fair to say there are two answers to ANY question like this, depending on the person asking, who might be:

1. the coder that wants to know what the limitations of their final site would be.
2, the coder that wants to know what little tricks the language can show off from a developer point of view.

in terms of the first point, i'd say there are no limitations as HTML is very basic in comparison to serverside languages so its unlikely there's anything HTML the server side lang couldnt tackle with ease.

as for the second, surely it's a matter of taste and preference.

obviously, i've based both my points on the fact of using perl/PHP for Web stuff. But i'm quite adament on the point that when I hit a wall with PHP as far as web design goes, then i may look elsewhere. otherwise, what's the point?

Share this post


Link to post
Share on other sites
Well, that's exactly the point -- there is no "wall" with Perl.  There's nothing to can't do... Perl is just about manipulating a bunch of strings, and guess what, that's what you spit out the browser anyway.  Consequently, I find Perl to be ideally suited for the task.

Share this post


Link to post
Share on other sites
[quote author=fenway link=topic=107138.msg429493#msg429493 date=1157573385]
Fourth, I couldn't live without hashrefs for everything, and I don't see that as native in PHP, though I might have missed it.

The list goes on and on... I couldn't ever abandon Perl.  Feel free to correct me if need be.
[/quote]

Since you made the invitation..

PHP references use C syntax, eg "$hashref = &$assoc_array".  However, variables are copy on write, including function arguments, so in most cases you don't need references.

For multilevel hashes, you can just write $assoc_array['level1']['level2'] = 'bleh';  It's not much different to perl really.  Is there a use for hashrefs which doesn't come under one of the above?  (that is, sharing data and multilevel structures)

I haven't hit a wall with PHP.. I think it is equal in power to Perl.  Just that perl is geared toward text processing, and php is geared toward web applications.  At my workplace we use perl for backend scripts, and php for the frontend.

Share this post


Link to post
Share on other sites
Well, AFAIK, Perl doesn't do copy on write, so if you want the reference, you need it.  I'm sure the syntax is similar -- but does PHP auto-vivify hashes?  I don't find anything about PHP particularly "geared" toward web apps, at least not as far as the core language, though I've only seen code examples.  But that's just me.

Share this post


Link to post
Share on other sites
Does autovivify mean to create automatically?  The default in PHP is to create all variables (including levels in multi-level arrays) automatically.  Like:

$var['count'] = 2;
$var['values'][0] = 0.1;
$var['values'][1] = 0.2;

I'm not sure if that's what you're talking about though..

If you then say "$values = $var['values']", you will get a copy-on-write copy of that part of the array.  "$values = &$var['values']" will give you a reference to that part of the array.

As far as usage goes, it's virtually the same as perl.  I found it easy to switch over.

Regarding "gearedness", it's the little things.. in perl you can write "while (<>) { s/..$// }", which is great for processing a text file.  In PHP, you can write "session_start(); $_SESSION['var'] = $_GET['var'];", which is great for a website.  $_SESSION is part of the language specification itself, as is $_GET and $_POST.

Once you've got enough skill in either language you can do anything though.  It's just the little things that are handled for you already which make up the gearedness.

Share this post


Link to post
Share on other sites
Agreed... and yes, that's what I mean by auto-vivify.

Share this post


Link to post
Share on other sites
I'd like to reopen discussion on this topic if I may. I've been using PHP for web coding for about a year now (nothing professional, just for fun). I'd like to expand a little to other programming languages, I'm considering Perl since its superficially similar to PHP. I not a programmer by trade (I'm a scientist/engineer), but I like to automate tasks (hence my little hobby of programming). Is Perl a good tool for this? I love working with PHP, but it seems that it really was built for HyperText pre-processing, and I'd like something that might be a little more powerful on the desktop (shell). Most of the little annoyances I end up automating are things at work, and unfortunately (like the rest of the world) we're stuck with Windows. Is Perl for me? If not, what other language(s) should I look into? (I've read the links posted earlier, they essentially were Perl guys ragging on PHP) What are the Pros/Cons of each?

Thanks!

Share this post


Link to post
Share on other sites
Perl is great for automation, though it's more native to *nix boxes -- however, I've had good experience working under windows as well.

Share this post


Link to post
Share on other sites
[quote author=fenway link=topic=107138.msg472830#msg472830 date=1164327471]
Perl is great for automation, though it's more native to *nix boxes -- however, I've had good experience working under windows as well.
[/quote]Any advice on a good book to start learning from? I've looked at the camel book and the llama book. I've done a fair amount of programming in VB and PHP, is the llama book a little too introductory? (Of course it couldn't hurt to review a little)

Share this post


Link to post
Share on other sites
Actually, I've never used a book, so I can't suggest any in particular.

Share this post


Link to post
Share on other sites
I talked to a programmer friend of mine, he suggested I look into Python (as an alternative to Perl). I've been scowering the internet looking for a good comparison of the two. Except almost all articles written on this topic turn into monster flames between to heated camps. I thought I'd post the few articles/blogs/forums posts that actually draw meaningful comparison between the two.

Best Article:
http://www.linuxjournal.com/article/3882

Good article if you look past the author's cynicism:
http://lists.canonical.org/pipermail/kragen-tol/2002-January/000660.html

Short differences:
http://www.wellho.net/forum/Which-language-to-use/Perl-or-Python.html

Python vs. PHP
http://wiki.python.org/moin/PythonVsPhp

Detailed comparison of almost all languages (code examples too)
http://people.mandriva.com/~prigaux//language-study/syntax-across-languages.html

I'm trying to decide which language to pick up next. Hopefully this will help other people trying to make a similar decision.

Share this post


Link to post
Share on other sites
[quote]Python is better than both php and perl.[/quote]

That statement is just plain rediculous. Each language has its place. I personally love Python and use it allot more than I do PHP, though I dont do much web dev anymore. When I do, I usually op for PHP because that is exactly what it was made for. Though I have been finding the django framework alot of fun lately.

Anyway, my whole point is that any language has its place. Its a bit of a falsity to say any language is better then another.

Share this post


Link to post
Share on other sites
I never said they didn't have their place but in the context of this conversation and on a technical level python is better than both is better than these languages. I am aware each language has its place, if I wasn't I would not use php. 

Share this post


Link to post
Share on other sites
"Better" must be used in context; otherwise, it's just subjective--an opinion. This conversation started with the question "Is Perl worth it?" and thus the answers have been "Well, it depends on what you're using it for...."

Share this post


Link to post
Share on other sites
Well, necessarily so... just like with any tool, hammer or otherwise.

Share this post


Link to post
Share on other sites
well... I know the OP was posed as a "is perl worth anything as a language," and I guess that's my fault for asking it that way, because I think what I really meant at the time was more in the context of "would it significantly help in the career field." 

I don't really argue that it has its own merits and faults like any other language.  But there are plenty of things out there that can "do the same thing," but just don't have the..'popularity' to really be worth trying to further a career on. 

On that note, I would certainly agree that knowing 2 languages is always better than 1. Or 3 is better than 2, etc. etc.. I would certainly not argue that the more versatile you are, the more jobs you will stand to get.  I guess I was looking for opinions on, for instance: in your own experiences in the industry, if you already had a decent grasp of php, would it really be an absolute necessity to try to take on perl as well, as something more than a "boosting your programming flexibility" thing? 

Share this post


Link to post
Share on other sites
Every data import I've done was easier in Perl (not that I've ever used anything else)... but it's just so much simpler, IMHO.  Personally, I find the web stuff pretty straightforward in Perl too, but that's up for debate.

Share this post


Link to post
Share on other sites
Depending on what source I hear it from, PHP is way better than Perl, or the opposite... So, I personally have no idea, but I would like to know if Perl is worth using my time on... If I only do web development, would anyone suggest I use anything besides PHP?

Share this post


Link to post
Share on other sites
If its only web development your interested in then Id'e say no, just stuck with php. Perl can't really [i]do[/i] anything that php can't in the web dev arena, I mean its simply just outputting html anyway.

However, it never hurts to get a few languages under your belt... see things from a different point of view. Its up to you really, but your not (IMO) going to see any huge advantage in Perl over PHP.

Share this post


Link to post
Share on other sites
[quote author=Nameless12 link=topic=107138.msg509752#msg509752 date=1169386942]
Python is better than both php and perl.
[/quote]
This is exactly the kind of thing you run into with these two camps. I can't even begin to list all the forum posts I found that were just huge flames. Its completely counter productive, and as others have pointed out, way off topic. I seriously looked into both languages, and there's [b]nothing[/b] you can do in Perl that can't be done in Python and vice versa. It really just depends on your style. Perl fits for me. I'm not a programmer by trade, (kind of a twisted hobby) so I like Perl's quick, cryptic, one-liners. Perl's philosophy is "There's More Than One Way to Do It", and they make a big deal out of making the interpreter and compiler smart so that you can say it however you want. The language tries to stay out of your way as much as possible. As a result things can get ugly, but that's the beauty of it. Python is more strict, and carries a heavy OO influence. Which may make for "better looking" code, but in the end its just about getting the job done (for me). I've just started working with Perl, so I'm definitely not an expert, but it works for me.

To draw on the PHP vs. Perl comparison, I can see lots of Perl influence in PHP, array_shift() would be the first thing that comes to mind. To code for the web, I stick with PHP unless you I need to run some complex system tasks or other extended functionality, which is where I think that PHP starts to get out of its league (it still can be done in PHP, but you don't use a hammer to screw in a screw). I can usually hold my own in PHP, Perl is superficially similar, so the transition was easy for me. Of course, I picked up Perl because I wanted to get [i]away[/i] from the web, which brings me to what I believe is Python's greatest strength (over Perl/PHP): compiled binaries. Granted you can do that in Perl too (not that well though, it's tough). I don't really need to distribute anything I write in Perl so I can live with out this functionality.

Bottom line, check them both out (don't use the internet, or you can reread all the flames I found earlier), and see which one is right for you. I definitely plan on learning Python later, its a great tool to have. Right now I need a "glue language" and Perl fits the bill for that (for me) perfectly. Go to Barnes & Nobel or something, pick up a Perl book and a Python book sit down and read through a couple examples and you'll know which one fits you best.

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.