
Learn Perl in about 2 hours 30 minutes - utkarshkukreti
http://qntm.org/files/perl/perl.html
======
wallfly
Over the past week I've read "Modern Perl", and will finish it later today:

<http://onyxneon.com/books/modern_perl/>

The ebook/PDF edition is free! It's a great book for learning (modern) Perl
basics if you're already familiar with programming concepts and another
language like JavaScript (which is where I'm coming from).

Actually, I think the knowledge and best-practices gleaned from the book will
help to make me a better programmer in a general sense (not just in terms of
the Perl language). It's well written, a pleasure to read and I highly
recommend it.

~~~
tedkalaw
Were you previously a Perl programmer at all? And are you learning it for any
particular purpose?

I've always wanted to give Perl a go but can't find something I want to use it
for.

~~~
wallfly
No previous Perl programming-experience. I've been consciously aware of Perl
since at least 1998 and even poked at the source code of some scripts here and
there, but didn't bother to really learn anything about it until recently.

A brief explanation; perhaps someone here will be inspired or is thinking
along similar lines:

I've been using an "object system" for JavaScript named Joose:
<http://joose.it/>

Joose is amazing and is, roughly speaking, a port of the Moose object system
for Perl to JavaScript. (Moose is mentioned in various comments below and many
times in the "Modern Perl" book.)

The principal author/maintainer of Joose v3 (Nickolay Platonov) has developed
an ecosystem of tools on top of Joose3 and for Joose-oriented distributions
(github.com/SamuraiJack). Much of their design is inspired by popular
distributions in Perl's CPAN (Nickolay has a strong background in Perl,
obviously). And some of them are still tied into Perl libraries, not simply
ports to JavaScript.

As node.js and its package manager NPM have evolved rapidly in the last 12
months, some of the Joose stuff is lagging behind and in need of an overhaul,
e.g. Nickolay's "JSAN plugin" for Dist::Zilla.

I've been wanting to help, but it's difficult to hack on Perl code if you
don't even know the syntax. Well, that's where chromatic's book has come to
the rescue! To be honest, it's been a real eye-opener and, as I suggested
earlier, I think this Perl learning-experience is actually going to be a big
boon for me in the near term and into the future. It's already allowing me to
view Joose and related libraries through new eyes.

~~~
chromatic
Anecdote which amuses me: I find JavaScript tolerable thanks to Joose and
other ideas borrowed from Perl.

~~~
wallfly
Not sure if you'd have any thoughts on this matter...

The JavaScript community as a whole (seen especially in the direction of
node.js + NPM) is moving away from global namespaces and toward the "module
pattern" and dependency injection (note: I had no idea what those terms really
meant 6 months ago).

Presently, Joose3 goes against that grain. For example, if in a node.js script
you:

    
    
       require('joose')
       if (Joose) { console.log(true) } // prints true!
    

Basically, the global namespace gets auto-populated with "Joose" and a chain
of namespaces below that. This is very Perl/Moose-like, of course.

When you define classes, roles, etc. you get similar behavior:

    
    
       Joose.Class('MyClass', {...})
       if (MyClass) { console.log('effectively stubbed in a global namespace!') }
       // does log that text to console, as Joose.Class() behaves that way
    

And in fact, Joose3 encourages you to embrace that behavior (with `use:`
builders and lots of discrete files) to arrive at a network of cross-
referenced namespaces which altogether form a library, and API usually.

To go with the flow, and especially to take advantage of emerging module specs
like AMD (commonjs thing), a redesigned Joose (i.e. Joose4) needs to eschew
global namespaces entirely:

    
    
       var myJuice = require('joose')
       ...
       // There should be no tie to a "Joose" namespace as such
    

But how to do that, and elegantly?

Any wisdom from the Perl community in that regard? Maybe someone else has been
trying to port Perl stuff to JavaScript/node.js and has found the perfect
formalism for translating from global namespaces -> module pattern +
dependency injection? Know any Moose wizards that would be willing to help
explore this matter?

~~~
chromatic
I haven't written a lot of Joose code, but I use anonymous classes and store
their constructors as attributes of a lexically scoped object I inject where I
need it, so as to avoid global pollution. So far it works nicely.

------
bbbbbbbbb
Perl is a really great language that i came to love over the years. First,
I've been writing PHP stuff then moved to Perl and experienced
Java,Actionscript,Javascript,Objective-C,Python... But all of them, Perl was
the most powerful and expressive language.

For those who learn Javascript, Perl object literal notation should be really
easy to get and if you do some jQuery stuff, many things should come naturally
to you somehow. Perl supports packages, closure, utf8 since many years whereas
they are just coming to PHP (It's a real pain to go back to PHP for some
projects... as it looks like a huge trash of functions in the global namespace
with no cohesion at all... working with array_ _, mb__ or preg_* functions is
such a pain... hopefully the doc helps in understanding the quirks of the
language). The integration of regex as an operator is so nice. q[] or qq[]
helps quite a lot and I quickly miss them... Controlling each instance of the
program flow in code is very powerful too.

I guess the very minimalistic OOP system shipped with Perl did not help get
Perl across the board of a wider range of company...

Obviously, this le/gend/ary image of unreadable code that one-liners, and to
some extend sysadmin community, gave to the language has left a very bad taste
in the mouth... and it is now very hard to get rid of.

when you look at <http://mojolicio.us/> or <http://perldancer.org/> for web
development, Perl::Critic that analyzes your code for bad coding habits(JSLink
like), perltidy that reformat your code to follow your conventions or
Devel::NYTProf to profile every line of your code... I don't even talk about
CPAN that has always get the job done for me in like 90% of the case...

I still have to find a language that offers such a powerful ecosystem.

And for those who wonder, Perl is very active here in Japan.

~~~
altxwally
> Perl is very active here in Japan.

Considering the amount of legacy Perl scripts that I have had to rewrite since
I got to Japan due to a lack of Perl developers that can mantain them, I'd
think that Japan's Galapagos argument does not work so much in this case. I
think that it is also losing strength around here.

~~~
bbbbbbbbb
It does not mean that Perl is not active in Japan though. Many big companies
in Japan uses Perl as the language of choice for their websites but indeed,I
won't say that it's not loosing some market share though.

------
bluekeybox
If you _really_ want to learn Perl, you _must_ install the read-eval-print
loop (REPL) utility. If you have never used this utility, I will have serious
grounds to doubt your Perl skills.

Unlike Ruby or Python (or most other modern high-level programming languages),
Perl does not come with an interactive REPL shell, which makes no sense at
all, since, due to Perl's obscure syntax, someone trying out Perl would
benefit at least twice as much from a REPL shell than someone learning Ruby or
Python. Fortunately, the Devel::REPL package remedies this. Installing it is
super-simple:

    
    
        $ sudo /usr/bin/perl -MCPAN -e shell
        > install Devel::REPL
    

Once installed, simply open your terminal and run:

    
    
        $ re.pl
    

Once you have the REPL shell running, you can pretty much copy-and-paste into
it examples from this tutorial (or any other) and watch what Perl has to say
in response.

~~~
btilly
_If you have never used this utility, I will have serious grounds to doubt
your Perl skills._

Doubt away.

I have never used that utility. Yet I have been programming Perl since the
90s, and am one of the top 10 posters on Perlmonks. (My nick there is tilly.)

Care to re-evaluate your criteria?

~~~
peteretep
I'm in exactly the same boat. I've been doing Perl for 14 years, and never use
a REPL. Occasionally I'll hit 'perl -e ""' on the command line, which I guess
is a similar idea...

~~~
bluekeybox
Hey I didn't mean to offend Perl long-timers. See my response to btilly...

Hacker News is a bit of an exception to what you find in the real world (where
3 years of experience with a language can be considered as better than
average).

------
michaelpinto
I've been working with Perl programmers for just about ten years now and the
one thing I've sadly learned is that while many folks claim to know Perl, but
only a small group can do it well. (although granted you can apply this
reality to any other programming language)

~~~
Swannie
"Write once, read never" comes to mind.

So many single/double char operators which need to be memorised with Perl,
before you can start comprehending the programs.

Not to mention Perl hackers used to pride themselves on super succinct code -
in certain circles it use to be popular to include one liners to do complex
stuff in email signatures.

(Not complaining though, Perl was the first language I used, and probably the
simplest for text file processing in CGI's back in the day.)

~~~
kamaal
How do you do that in other languages? Whatever language that you will ever
use will require you to understand and to a degree memorize your usual
keywords, operators and syntax elements and rules concerning interplay between
them.

Regarding other stuff, building good software requires understanding a lot of
things which have nothing to do with Perl. Understanding concepts like
recursion, closure, OO, functional programming concepts etc etc. These have to
be first understood in theory. The Perl syntax is only a notation in which you
express your ideas. Besides that designing good software requires people to
understand design patterns, designing maintainable software requires people to
work on large project under sound practices. Writing fast and efficient
software requires people to learn Algorithms and data structures. And so on...

These principles remain the same regardless of the programming language you
use. Then why is it that only in case of Perl people hold the language
responsible for everything. To be frank, I have seen crappy code more often in
other languages than in Perl. I have seen over abuse of certain element like
XML in Java, and now these days Python.

The fact is if your technology community is huge you get a lot of crappy
people along with your usual set of good people. This happens for various
reasons, Everybody wants to learn something that is famous as it helps for Job
reasons.

Perl's strength apart from your usual language kit is CPAN, language tools to
produce highly useful rapid scripts in time. Heavy data lifting, data munging.
A gentle glance at things like Moose, Modern Perl, Devel::Declare and all
associated software with them(Catalyst, DBIx::Class), will show you the genius
of Perl community in coming up such great stuff in time.

------
TheRevoltingX
Perl rocks, I can testify to this:
[http://4.bp.blogspot.com/_Vtq6sCdzyKs/TK8Fooqqt9I/AAAAAAAAAG...](http://4.bp.blogspot.com/_Vtq6sCdzyKs/TK8Fooqqt9I/AAAAAAAAAGY/AdcMq7zxYUA/s1600/solomon_single_server.png)

I built a 2D mmorpg using Perl and Erlang. The languages a lot of people whine
about when it comes to syntax. Syntax is the LAST thing I had to worry. I'm
really happy that I chose those two languages.

------
mellery451
I do wish he had mentioned the smart match operator ~~ as it nearly eliminates
the confusion between EQ and ==. Of course, if you're dealing with legacy
code, then you still need to understand both (or all three), but new coders
might be well advised to start with smart match.

~~~
mjd
"Smart" match is a pile of shit, and anyone reading the manual description for
it should conclude the same. You can't know what it does unless you can
remember the details of a 23-item table.

It's undergoing major revision, and not a minute too soon.

~~~
koenigdavidmj
Is it that bad in Perl 6 too?

~~~
chromatic
No, because Perl 6 has a coherent type system.

------
ChuckMcM
Nice concise writeup. The only important thing he missed as far as I can see
is that the '..' operation can create anonymous arrays of sequences of
characters too so 'a' .. 'z' gives you an array of all the letters between 'a'
and 'z'.

~~~
jlarocco
Not as useful as 'a'..'z', but the '..' operator works on strings, also. For
example, 'aa'..'zz'.

------
pitchups
Wish there were similar ones for all the other languages - PHP / Python etc. I
always thought that most programmers and web developers experienced in one
language can quickly pick up the major features of another lanaguage, if there
was a quick overview of this sort. Know of any sites that do this? Maybe this
is a great opportunity for someone to put together a site like that?

~~~
benologist
Not just an overview but something where you pick the languages you know and
it shows you side by side examples doing the same thing.

I know there's a site that does that (can't remember the name) but having it
side by side with a great overview like this would be awesome.

~~~
chromatic
Perhaps you're thinking of PLEAC?

<http://pleac.sourceforge.net/>

Or perhaps Rosetta Code?

<http://rosettacode.org/wiki/Main_Page>

~~~
benologist
Rosetta Code's the one I was thinking of, but I really dislike their structure
- I never want to see how to do something in _dozens_ of languages, almost all
of which aren't relevant to me.

What I would love to see is:

1) select language you want to learn

2) select languages you already know

3) you get a cheatsheet like the OP that goes through all the basics (and
maybe even more detailed), and all the code samples are changeable ala MSDN
where you click "C#" or "VB.NET" or whatever to see the code in that language:
[http://msdn.microsoft.com/en-
us/library/system.drawing.bitma...](http://msdn.microsoft.com/en-
us/library/system.drawing.bitmap.aspx#Y4876)

~~~
pitchups
Perhaps someone can use Rosetta code as a starting point (their content is GNU
licensed) and build a site that does what you are suggesting - where it only
shows you the features for the languages you want to learn, based on the ones
you know.

------
ez77
As an aside, the author's clarification [1] of the many terms related to the
UK, Britain, etc. are very enlightening.

[1] <http://qntm.org/uk>

------
known
<http://perldesignpatterns.com/?PerlDesignPatterns>

------
d2
Sam, you've certainly made an enemy out of every member of the Perl community
with this sarcastic and incomplete post.

Once you've gotten through OReilly's beginner Perl books and "Programming
Perl", if you truly want to learn how to scale Perl in the enterprise, read
Damian Conway's Object Oriented Perl. Once you can write solid consistent OO
Perl, read "Apache modules with Perl and C".

~~~
benatkin
> Sam, you've certainly made an enemy out of every member of the Perl
> community with this sarcastic and incomplete post.

What does the _Perl community_ mean to you? It must not include Sam.

Is it people who organize and participate in conferences and get indignant at
the slightest negative comment?

~~~
sigzero
No, we are not all like that. Fortunately. The author states:

"A bunch of new people started at work and we use a lot of Perl in our
department. So I put together some information about Perl and I thought it
might be worth sharing so here it is."

For that purpose, it is fine.

------
doctoboggan
Would it be beneficial to know this alongside of Python, or is it more used
instead of Python?

~~~
buckwild
I personally found that I didn't need Perl at all. I am a bioinformatics
programmer/scientist and Perl was the first language I learned. I find that
whatever I can do in Perl I can do with bash/awk/sed--and whatever I can't do
with bash/awk/sed I can do in Python. I've never been happier.

~~~
jrockway
Perl's advantage over bash/awk/sed is that you can test, organize, and
maintain code more effectively. This may not matter if you are programming to
solve tiny unrelated problems, but it's a waste of effort if you are doing
similar things frequently.

Python is basically Perl but with different syntax, libraries, and community.

~~~
Cushman
Out of curiosity, what do you consider to distinguish one Turing-complete
language from another aside from those three traits?

~~~
jrockway
Semantics. For example, writing a program to read "2 + 2" and evaluate the
result is going to be very different from Perl and Python in Java or C++.

------
lelele
It is not what Perl you know that will hurt you, but what you don't know.

------
vrode
I hope that the first thing you learn is how to pry open a casket.

------
unshift
not mentioned in the article is that apparently Moose is a really good OO
system for perl, but (in my opinion) about 10 years too late.

~~~
chromatic
How is it too late? Ten years ago, significant pieces of Moose did not exist
_anywhere_.

You can make the argument that if Perl 5 had had a better OO system not
borrowed from Python, Moose might not exist now. That may be true in part, but
I suspect significant pieces of Moose would still have to exist.

------
chaostheory
Question: Why don't people transition to Perl 6?

~~~
bluekeybox
Not enough people on the bandwagon, competition from Ruby/Python/JVM languages
on the high end and Perl 5 on the low end, and last but not least the fact you
can't use libraries written for Perl 5 with Perl 6.

I wrote a medium-sized project in Perl 5 two years ago. It is my day job right
now to work on it. I have very little interest in rewriting it from scratch in
any language, but if I did, it would probably be either Ruby or something on
the JVM.

~~~
chaostheory
Good point about Ruby. I forgot that it's the good looking and smart bastard
child of Perl.

------
kaichanvong
OH: "I dont believe it is possible."

------
qusiba
Studied Perl before Python years ago. Never got a chance to actually use it,
whereas Python became one of my favorite languages.

------
creativityhurts
But why?

------
berserkpi
Sure, just in case you really want to learn Perl...

------
derrickpetzold
Oh my why would anyone want to lean Perl anymore? Unless you are working with
a legacy codebase learn Python, Ruby, Java, C#, Erlang, Scala, Haskell... in
other words run the f away from Perl if you can unless you are into S&M.

~~~
chromatic
_Oh my why would anyone want to lean Perl anymore?_

Because it's powerful, it's easy to start, it's flexible, it's productive,
it's ubiquitous, and it has an unparalleled extension ecosystem devoted to
quality and ease of use.

~~~
derrickpetzold
lol so do all the languages mentioned above plus they are prettier.

~~~
rjbond3rd
I don't think you read what you're responding to. How can they all have an
"unparalleled extension ecosystem"?

~~~
derrickpetzold
Thank you I did read the post. Python has pypi. Ruby has gems. I'm not going
to google the rest but if they don't have one there is no reason why they
can't.

And FYI pypi is better than CPAN so all the other stuff in the that post is
crap imho. I was a Perl dev for ~10 years. Now have about 5 worth of Python.
So thank you.

~~~
chromatic
_I'm not going to google the rest but if they don't have one there is no
reason why they can't._

That somehow fails to convince me that other language ecosystems parallel the
CPAN in breadth, scope, maturity, and ecosystem. See CPAN Testers, for
example.

~~~
derrickpetzold
Oh my apologies I wasn't trying to convince anyone of anything if that's what
you are thinking. I was only stating fact based on my experience but that's
okay just downvote this and make yourself right.

~~~
kamaal
Nobody was down voting you to make themselves right. But the remarks that you
made about CPAN to be frank didn't make any sense at all to anybody who has
worked with CPAN seriously over years.

Both in terms of quantity and quality CPAN beats any other scripting ecosystem
by a very great margin. And its really not about the number of the modules.
That many number of modules would not have been possible if Perl(syntax,
extensions system) was not flexible enough to allow them.

The traditional approach used by languages is to first build a set of
semantics define a syntax and standard library for it. Then any other
development in that language happens through frameworks and libraries. Perl is
special in this case that Perl allows syntax extensions through modules. There
fore you will find not just Modules to do your task, but also modules that add
and extend to exiting Perl syntax with sugar. Perl 6 extends this concept
further through grammars.

How often and how many language are there today(Counting Python and Ruby
especially) that can add something like Moose(Moosex extensions) and other
syntactical extension to their language, without breaking backwards
compatibility?

Python took around 8 years and broke backwards compatibility to make as little
changes as context of a for loop and print statement. Now imagine what it
would take Python to fix its object system or its scoping problems.

~~~
derrickpetzold
Thank you for the excellent reply. That was response I was hoping for. I don't
know everything and I appreciate you talking on point and not just pressing
the down arrow because someone said something you don't like.

Regards,

~~~
berntb
>>... not just pressing the down arrow because someone said something you
don't like.

Sigh... :-)

He _started_ :

>>Nobody was down voting you to make themselves right. But the remarks that
you made about CPAN to be frank didn't make any sense [etc]

Are you really surprised about the down votes...?

~~~
derrickpetzold
> Sigh... :-)

I honestly have no idea what you mean by that :).

> Are you really surprised about the down votes...?

For that post of course not. For the others yes.

I can only assume you are coming from this viewpoint

"Please avoid introducing classic flamewar topics unless you have something
genuinely new to say about them."

and no I don't think I had anything genuinely new to bring but I how could I
know about something I didn't know about.

I guess what I am really saying if people can't acknowledge the flaws in a
thing how could they ever make it better. And to say even more if they can't
vocalize their reasoning how does downvoting make it okay but I am sure that
is another thing I have missed.

~~~
berntb
>>I can only assume you are coming from this viewpoint

My trivial point was that your claim about the down votes was contradicted in
the first sentences. It seems you missed that, too.

>>if people can't acknowledge the flaws in a thing

Quite fun to do personal attacks like that after such creative way of
misreading.

Edit: Sorry for wasting time/space, I am easily trolled.

~~~
derrickpetzold
Hi. Thank you for taking all the things I said out of context. I am going to
try my best to do the same despite the fact that I believe this is what HN is
trying to avoid, moderator.

> My trivial point was that your claim about the down votes was contradicted
> in the first sentences. It seems you missed that, too.

I am sorry you think your thoughts are trivial and despite your grammatical
errors I would love to know how a first sentence can be plural. I have no
doubt that I missed a lot things prior. That was my entire point of my
following posts. Maybe if I knew which first sentence you were referring to I
could have a better response.

> Quite fun to do personal attacks like that after such creative way of
> misreading.

There were no personal attacks in the previous posts unless of course you are
Perl. In this post maybe there are many only because you made it so.

And I would appreciate if you read this small thread, moderator, and came back
with an intelligent reply.

Yes I could have not been a dick on this but you reap what you sow.

Edit: Thank you for trolling moderator.

~~~
derrickpetzold
haha you crack me up HN. So I get downvoted but the self confessed moderating
troll doesn't. That's awesome and for that I give you this

<http://www.youtube.com/watch?v=boh92DrYEWs>

