Discover the best of the web!
Learn more about Digg by taking the tour.
Learn Perl in 10 easy lessons - Lesson 1
linuxforums.org — Larry Wall created a scripting language in 1987, which he called the "Practical Extraction and Report Language". It was designed as a text-processing language for Unix operating systems. Various tools and languages already existed (Unix shells, sed, awk, C...etc) and programmers usually used many of them together.
- 1310 diggs
- digg it
- royall64, on 10/12/2007, -35/+4Welcome to the front page, buddy.
- JacNet, on 10/12/2007, -18/+4Why do you always get Dugg down?
- noerrorsfound, on 10/12/2007, -16/+4Because he makes pointless comments.
- ufia, on 10/12/2007, -15/+36Perl lesson #1:
#!/usr/bin/perl
print "Hello world!";
Perl lesson #2:
{{ } { } ! et {"} nc # ]} {$} { #}
% { c} & { $} ' ex ( fo ) } * -1 + {;s} , { f} - {u . {h } / (a
0 oc 1 { k} 2 {($} 3 ac 4 { -} 5 P} 6 {{ 7 {{}} 8 { p} 9 {) }
: 55 {;} { s} )* ? ar @ { A bi B {c } C {[i}
D {n E ^P F pp G k] H x) I }} J pr K {r } L {
Here you go, you're now ready to code in Perl, knock yourself out. - johnc79, on 10/12/2007, -10/+5@ ufia
Yeah, that really teaches me Pearl. Some people went to school for programming, some for engineering, some for business.... Why kick sand in someone's face when they're trying teach people something they're interested in? - johnc79, on 10/12/2007, -7/+2Anyone doing a tutorial on how to not embarrass yourself by double posting when using Digg Comments :-/
- Fascist, on 10/12/2007, -17/+21"Pathologically Eclectic Rubbish Lister."
- vhold, on 10/12/2007, -2/+9Ah come on why is this being buried?
Larry Wall jokingly calls it this himself in his books. In some ways it's actually a very apt description because Perl purposefully draws from many languages/environments. And well.. programmers are often tasked with listing rubbish, which Perl does excel at. - Ulrika, on 10/12/2007, -0/+6The parent was dugg down by folks who know perl well enough to stick up for it but not well enough to know its history. That amuses me. :D
- CovardeAnonimo, on 10/12/2007, -0/+3firts thing i thought about when i saw this link on thf front page was posting that joke.
i learned about this alternative meaning to "PERL" from the description in a debian package, i didn't know it came from larry himself. it's refreshing to know people can laugh at themselves. larry seems to be one of those guys.
- vhold, on 10/12/2007, -2/+9Ah come on why is this being buried?
- amightywind, on 10/12/2007, -11/+8Maybe in 20 more years Perl6 will be complete.
- brundlefly76, on 10/12/2007, -2/+5From the looks of it I'll still use Perl 5 anyway.
- joaob, on 10/12/2007, -6/+4gaming digg in 10 easy lessons.
- Jo9100, on 10/12/2007, -15/+3Who wants to learn perl anyway?
- artanis, on 10/12/2007, -4/+2I did. And now I know it.
- TroubleInMind, on 10/12/2007, -5/+12I heart perl.
- xanbu, on 10/12/2007, -3/+3@brundlefly71 really? I haven't missed it. Again I'm not knocking Perl. I was its biggest fan. However if someone wants to learn a language there isn't a good reason to learn Perl unless its required. Please review this; http://www.diveintopython.org/toc/index.html. Thanks.
- mrynit, on 10/12/2007, -13/+10i thought perl was dead and python was the new big lang.
- drjones78, on 10/12/2007, -0/+9Perl is a good skill to have. There are many enterprises with perl still gluing their entire operations together. Know perl well and you have job security. This is not, contrary to unknowledgable public opinion, because perl is only maintainable by the original author as so many like to say (well written perl is as easily maintainable as any other language, provided the maintainer knows what he/she is doing), but because there are almost no new developers jumping in the pool. Perl guru's are in good position to demand lots and lots of money at the moment.
- Kniggit, on 10/12/2007, -0/+7I learned Perl when I was designing chips. It was a more powerful and integrated language for the "quick and dirty" stuff than sed/awk/grep/shellscript when it came to dealing with parsing files for making chips, but less cumbersome than C or C++. In fact, I pushed pretty hard at my alma mater for it to be taught to people along with TCL in the curriculum. I've designed an entire automation application for QAing analog intellectual property on chips with it.
Interestingly enough, around the end of 2000, Python started coming into its own very slowly, and there were lots of automation scripts for chip design tools being done in Python at my company. Had no idea they'd be the trailblazers that they were. Nowadays, Python and Ruby have a pretty big following and have taken the lead. Perl isn't going anywhere, though, because it occupies the niche between shell scripts and full-on programming languages nicely. - Archon810, on 10/12/2007, -3/+8@drjones78: Really? I thought everybody and their mother knows Perl compared to c for example.
But then again, I guess you're right about job security since I was able to get a job 6 months ago right out of college doing pure Perl + mysql and it pays ~75k.
As far as my experience with Perl, I ***** love it, there's no other word. There's a funny quote about the freedom and forgiveness of Perl that only Perl programmers will understand: somebody was complaining about how hard Perl was to learn. Response: “If you have trouble coding in Perl, just let your cat walk on the keyboard for a while. Then you just have to debug it.”
P.S. Larry Wall hates when people call Perl 'perl' (first letter should be upper case). - brundlefly76, on 10/12/2007, -2/+8Not if you want a job.
Dice job postings:
Java 14662
.NET 8031
C 7843
C++ 7482
Perl 4769
COBOL 1240
Python 752
Ruby 290 - vhold, on 10/12/2007, -0/+4"P.S. Larry Wall hates when people call Perl 'perl' (first letter should be upper case)."
Well, when referring to the -language-, yea. They like the clarify that Perl is the language and that perl is the compiler/virtual-machine/runtime-environment/etc (basically.. the actual program) - xanbu, on 10/12/2007, -7/+1I think you are right. I grew up on it for ten years. Perl it is still near and dear to me but Python is where its at. I wouldn't suggest someone learn it unless they needed to. In my experience the only people that still use Perl are the ones that have to or the ones that just don't know any better.
- brundlefly76, on 10/12/2007, -2/+10@xanbu
One reason why everyone should know Perl:
CPAN
It is the envy of all other languages.
Every other language on earth refuses to address one or more of the following in its modules: standardization, organization, documentation, distribution.
The only exceptions are the languages which have chosen to follow CPAN. - Markpdotcom, on 10/12/2007, -9/+2Exactly! Why would anyone want to learn a dead language? Hurray, lets all learn latin!
- vhold, on 10/12/2007, -2/+5I can't help but think that it's something of a newbie misconception that Perl is dead. It inspired php, ruby and python, and all those things are newer and shinier, but seriously.. Check job sites for Perl.. check out the activity on CPAN..
http://www.tiobe.com/tpci.htm
http://search.cpan.org/recent
You could literally spend months pouring over the open code and solutions that are in CPAN.
Perl 5 is extremely mature. It's one of the reasons you don't see it's name up in lights so much anymore. It's a work horse, not a show horse. - veracon, on 10/12/2007, -0/+4I'm a Python guy and all, but I do agree that Perl is far from dead - and that CPAN is the perfect example of this. I mean, sure, Python has its cheese shop (PyPI) with what, 2000 packages (?), but CPAN is just so amazingly extensive. Of course, as the "new-school" languages (be it Python, Ruby, you name it) grow, they'll also have larger package indexes, but for library support right now, Perl is where it's at.
- drjones78, on 10/12/2007, -0/+9Perl is a good skill to have. There are many enterprises with perl still gluing their entire operations together. Know perl well and you have job security. This is not, contrary to unknowledgable public opinion, because perl is only maintainable by the original author as so many like to say (well written perl is as easily maintainable as any other language, provided the maintainer knows what he/she is doing), but because there are almost no new developers jumping in the pool. Perl guru's are in good position to demand lots and lots of money at the moment.
- hackwrench, on 10/12/2007, -0/+9Did the page have to set fixed width lines though? Especially such long ones? Scrolling side to side isn't fun.
- backrash, on 10/12/2007, -0/+3all the code is on one line too. i was looking forward to learning perl too. :(
- petercooper, on 10/12/2007, -4/+2In other news, "Learn APL on the System/360" has been a big hit at the bookstores.
- DiscoLando, on 10/12/2007, -2/+6Incorrect. Larry Wall did not attribute the widely known acronym for Perl - it's a backronym.
Wall got the name from the Bible - he is a Christian, after all. Perl is derived from the parable of the "Pearl of Great Price".- SteveyDevey, on 10/12/2007, -2/+2I was also going to mention this if no one else had. Why are people digging this down?
- vhold, on 10/12/2007, -0/+2I think his main goal was for it to be a 4 letter word that was easy to type and spell. There's obviously more story to how he ended up on perl, but that was really the main thing.
- tehmoth, on 10/12/2007, -0/+2he wanted to call it Pearl, but there was already a programming language named pearl
- simpleman, on 10/12/2007, -10/+1well I do not either of them...I am just learning Linux so programming is not something that I know yet, so I can not comment on Pearl. From what I read online you are either told to learn pearl or python as a beginning language.
- glenathon, on 10/12/2007, -7/+2....from the guy named 'simpleman', ladies and gentlemen.
- tehmoth, on 10/12/2007, -2/+1PEARL is Process and Experiment Automation Realtime Language, this article is about Perl.
- AlfaWolph, on 10/12/2007, -1/+1Haha Dugg for that one, Glen.
- select, on 10/12/2007, -4/+6Perl gets the job done!
- maehem, on 10/12/2007, -8/+5In Soviet Russia, Perl learns you!
- sker, on 10/12/2007, -1/+2Funny, I thought Soviet Russia jokes were gone.
- sembetu, on 10/12/2007, -1/+1Next Week...
"Assembly and the AS/400 in 10 Easy Steps"
Hold your breath.- PopcornDave, on 10/12/2007, -0/+1Now if it was PDP-11 in 10 easy steps, I'd be interested.
- subxero37, on 10/12/2007, -1/+8Perl is a great language, but it (IMO) suffers from the same flaws as PHP -- it's incredibly difficult to read. There's tons of symbols all over the place, I can't easily tell what code would do something the best way, and there are far too many ways to accomplish the same thing. Too many dollar signs!
(Oh, sorry, if my comment was useless or not well-thought-out, I just got out of surgery the other day -- maxillary osteotomy -- and I may not be "here" yet.)- Archon810, on 10/12/2007, -0/+5I love the $ signs. After Perl I can't read c code anymore cause u never know what u're looking at (semi-joke).
- iamdravenman, on 10/12/2007, -0/+2how is it a flaw to have more than one way to do the same thing? Maybe one way is better for one thing than another way would be. If there was only one way to get everything done, anybody who can remember a simple math formula could program and it wouldn't be that tough... not that PHP is tough anyway.
Start small, build from there.
Oh, and it's only difficult to read if you write it that way. - MrMuskrat, on 10/12/2007, -0/+2Perl written with a decent style is readable by any one. The problem is that when people go looking for examples to use when comparing Perl with any other language, they like to find the hardest code to read and use that as their proof that it's unreadable. You can't compare Perl golf or obfuscations with normal programs from another language; that's a biased comparison.
- ermau, on 10/12/2007, -0/+1Comparing the readability of Perl to PHP is insane.
- nadadingsda, on 10/12/2007, -8/+6Lesson 0: Use Python instead
- tehmoth, on 10/12/2007, -3/+2i'd rather not rely on significant whitespace not being lost somewhere. By all means, learn Python to be trendy, but also learn Perl seeing as it actually comes installed on more operating systems than python will ever be ported to.
- ermau, on 10/12/2007, -2/+1Let me fix that for you:
Lesson 0: Use PHP instead.
- cronin1024, on 10/12/2007, -0/+6I've taken to reading the O'Reilly book Learning Perl and I must say that it has done an excellent job of teaching a language that some might consider incomprehensible (mainly due to the regular expressions and the special variables like $_, $!, @_, and the like) and making it something that can be easily understood. I must say that now I know the basics of Perl, going back to ordinary shell programming seems like a nightmare. I might even stop programming in C except for the code that I need to be compiled. Yeah, anyways, Perl is just one of those languages that if you use *NIX, you should know.
- dak1486, on 10/12/2007, -1/+5i ♥ perl
- N3wtR0ckn13, on 10/12/2007, -4/+3Lesson 1 cut a hole in the box...2
- monkeymagik, on 10/12/2007, -1/+5should you really trust a programming tutorial from someone that can't create a webpage that resizes to your browser?
- ucbmckee, on 10/12/2007, -8/+2Perl is what separates the untrained hackers from the computer scientists/engineers. The latter group would never use something so unmaintainable, so grammatically horrible, so completely shyte. It's like putting square wheels on your car - it may get the job done, but dear god, there are better options!
- xanbu, on 10/12/2007, -0/+0@Halbyrd It seems to hate me even more, I'm can't seem to reply to the right comment. Anyways could you please elaborate on the "syntactical quirks". I thought it was quirky at first but then it all started to make sense and in most cases they make it harder to write unreadable code which is far to easy in Perl. As for emerge perhaps its the brittleness that is the problem not the language.
- edcheng, on 10/12/2007, -8/+1RUBY!!!
- gdm9000, on 10/12/2007, -4/+7I've been reading the recent tutorial about Ruby posted on Digg recently, and I have to say, after a few hours, I hate what I see!
* puts and gets? WTF? Let's add the most unreadable parts of C to a new modern language. In Python, it's 'print'.
* WTF is the === operator? Nobody's going to guess what that is... I've never even heard of that operation before.
* There are both .. and ... operators for arrays? WTF? That's so unreadable that I know it will be a future bug in my code!
* OK, everything is an object. So, consider the following: mystring = %w( Hello world! )
WTF is %w? It must be a keyword function call, not an object. But % seems to indicate a builtin operator, not a function. ???
Why do we have so many ways to declare a string? I just want to declare a simple string:
'* "Inches/yard: #{12*3}" != 'Inches/yard: #{12*3}'??? Unintuitive.
* %q{Hoagies & grinders!} OK, I get that %q is an alias for ', but WTF is %q? Is it a function? An object? An operator?
* %Q;#{"Navy beans! "*3}; OK, I get that %Q is an alias for ", despite the fact that it's not intuitive, but WTF is ; ?
* my_string = - gdm9000, on 10/12/2007, -4/+2Hey, Digg won't let me finish my comment! WTF???
* my_string = - gdm9000, on 10/12/2007, -4/+1Ah, I think Ruby's
- gdm9000, on 10/12/2007, -5/+2AUGH, Ruby's << operator screwed up my comment; here is the rest...
* my_string = <<MY_STRING
This is a multiline string
MY_STRING WTF is this?
* my_haiku = %w( my dog digs it heren ) OK, I get that %w is a string tokenizer function(operator?)... But WTF? You can declare a string as a parameter without any apostrophes/quotes/etc? Yet another way to declare a string...
AUGH! How many ways do we need to declare a string?
Contrast this with Python:
* 'Hello world!' and "Hello world!" are logically the same. There's no escape character for quote or apostrophe. If you want an apostrophe in your string, use quotes. If you want quotes in your string, use an apostrophe.
* """ Here's a multiline string
with an apostrophe. """
* ''' I declare in another multiline string with quotes,
"Hello, World!" ''''
I heart Python! - Halbyrd, on 10/12/2007, -2/+3@gdm9000
*laughs* Apparently, Digg hates Ruby code as much as you do. And you're right, those are some serious Whiskey Tango Foxtrot moments there. - Halbyrd, on 10/12/2007, -1/+1/* continued */
One problem I can easily see with Python's lack of escape characters for ' and " is the need to print a string which contains both.
An example from C++ (yes, I know, it's an ugly hack on top of a cryptic language, but it's the one I know most intimately, so please bear w/me):
cout - Halbyrd, on 10/12/2007, -1/+1Oh, I give up; Digg's comment system hates me. I've tried to retype this d*mn comment three times already, and it rejects the changes every time.
The salient bit is this: Python has some syntactical quirks that make certain tasks needlessly complex, in order to preserve certain a certain aesthetic. Perl code, OTOH, can be as hairy or as elegant as you like, as the syntax is designed to conform to the programmer, not the other way around. I'm sure Python has some characteristics to recommend it as an alternative to Perl in certain situations, but for what Perl was designed to do--shell scripting, list processing, and rapid prototyping--it works well, and it doesn't get in my way.
Python's off to a good start, but it's nowhere near as robust as Perl--see the numerous problems with brittle ebuild scripts that break on minor version changes in Gentoo Portage for details. - LordVoldemort, on 10/12/2007, -1/+1I thought Gentoo scripts are bash.
- Slackwise, on 10/12/2007, -2/+1@gdm9000
puts and gets? Yes, they are the standard in Ruby, but print also exists. Bnd since when did C utilize a puts/gets function? The most common way in C for printing to STDOUT is printf() and reading from STDIN is scanf(). You must be a very confused boy.
irb(main):001:0> foo = """
irb(main):002:0" this
irb(main):003:0" is
irb(main):004:0" a
irb(main):005:0" milti-line
sirb(main):006:0" string """
=> "nthisnisnanmilti-linenstring "
irb(main):007:0> print foo
this
is
a
milti-line
string => nil
irb(main):008:0>
I'm quite lost at what you're bitching about. You obviously don't know Ruby, so I don't think you have the right to complain about it.
Also, those other ways of declaring a string (such as <<, %Q(), and the sort) were adopted from Perl.
- gdm9000, on 10/12/2007, -4/+7I've been reading the recent tutorial about Ruby posted on Digg recently, and I have to say, after a few hours, I hate what I see!
- paulmetzger, on 10/12/2007, -0/+4Worthless!
Summary:
Perl is a unique language installed by default on most every linux distribution run through an interpreter that can either be invoked manually on the command line or with with a line at the top that tells the shell where the perl interpreter is. Here's the code for hello world.
End of lesson.
Seriously, this is 1/10 of the way to learning Perl? give me a break! - bstamour, on 10/12/2007, -0/+4man the first paragraph already gets its history wrong. Perl isnt an acronym for "Practical extraction and report language" as the creator called it perl without having a special meaning. Later on those who used it created a backronym for it.
- JamesNewton, on 10/12/2007, -0/+1Are you freaking kidding me? This useless "tutorial" on how to write "hello world" in perl gets to the front page?
- kettle, on 10/12/2007, -0/+1dugg down for awful html. what's with having to scroll sideways for a millenium? not very clever if you ask me. maybe the ie or opera or safari experience is different, but this page renders like a piece of crap in firefox.
- ideadude, on 10/12/2007, -1/+1Here's an alternative intro to Perl. Some notes from a course a friend of mine taught a few years back:
http://andrew.absurdlycool.com/class/- MrMuskrat, on 10/12/2007, -0/+2Dugg down for not teaching about proper variable declaration, enabling warnings or using strictures.
- AlfaWolph, on 10/12/2007, -0/+3For those really wanting to learn Perl I can wholeheartedly recommend the O'Reilly llama book (yes, it has that coveted distinction) aptly called: "Learning Perl". Great, concise explanations that really show off the limits and gotchas of the language and exercises that are challenging and aren't merely cut and pastes of the lesson material.
Now if only something half as good existed for Ruby.. - xanbu, on 10/12/2007, -3/+0@brundlefly71 really? I haven't missed it. Again I'm not knocking Perl. I was its biggest fan. However if someone wants to learn a language there isn't a good reason to learn Perl unless its required. Please review this; http://www.diveintopython.org/toc/index.html. Thanks.
- mikewilsonuk, on 10/12/2007, -4/+1That is 10 years too late. Anyone who doesn't know Perl would make better use of their time learning Ruby or Python instead. Unless they have a very good reason to need Perl.
- meBigGuy, on 10/12/2007, -0/+3Very Lame Site -- Useless as a tutorial.
My advice to people learning Perl is to not use $_ . Write ($line = ), rather than ()
My favorite test question for Perl programmers is " What is a Pseudo Hash?" (only because it is such a weird useless thing). I keep hoping I will need it someday. I wonder if that will be in Lesson 10?
The coolest thing about Perl is that you can just start writing code without thinking about how the language wants you to structure your task.
People who say Perl is cryptic should be required to learn Make.- meBigGuy, on 10/12/2007, -0/+1too bad dig comments removed my example code. Ignore everything after Write on the second line.
- tsornin, on 10/12/2007, -0/+0Try http://www.cgi101.com/learn/ ... it won't make you an expert Perl programmer, but it will get you started, and you'll be able to build a few web programs right away. It's geared towards non-programmers.
- MrMuskrat, on 10/12/2007, -0/+2Bad tutorial for many reasons: horrible formatting, no mention of warnings or strictures, all variables are global, etc...
If you really want to learn Perl then buy the Llama; Learning Perl, Fourth Edition by Randal L. Schwartz, Tom Phoenix and brian d foy http://www.oreillynet.com/catalog/learnperl4/
While you are at it, pick up a copy of the Learning Perl Study Guide aka Student Workbook. http://www.theperlreview.com/learning_perl_study_guide/
After that, set up an account at Perl Monks and read everything you can starting with the tutorials. - sharjeelsayed, on 10/12/2007, -1/+2http://www.sthomas.net/oldpages/roberts-perl-tutorial.htm
- treehead, on 10/12/2007, -0/+1Page formatting needs major help. No digg.
Digg is coming to a city (and computer) near you! Check out all the details on our