top | item 10637789

Perl 6 Introduction

192 points| bane | 10 years ago |perl6intro.com | reply

105 comments

order
[+] s_kilk|10 years ago|reply
I've got to say, perl6 is really, really fun to play with. (and I say this as someone who had not used perl before)

So far I've gotten the impression it's made by a bunch of smart, friendly hackers who care about quality in their software.

To anyone reading this, I'd strongly recommend casting aside any preconceived notions about perl and giving perl6 an honest shot.

[+] user9756|10 years ago|reply
I'd like to take perl6 for a spin. However, other than playing with it I'm not sure how it compares to say python or ruby in terms of strong sides. I mean what are the cases perl6 would shine in comparison? (NOT TO FLAME! I'm asking for ideas to when perl6 would be an interesting tool for the job. AFAIK it had a good string manipulation ~ also I'm still reading the tut and currently it feels very bash and somewhat ugly (although helpful) with the % & @ prefixes).
[+] user9756|10 years ago|reply
Great (basic) introduction with exception to the regex chapter because it felt like an introduction to regex instead of the regex features of perl6.

Some things I found interesting (in addition to what s_kilk mentioned and linked to and others have already mentioned some of them) * Gradual typed! * Multi subroutine * Hyphen in variable names * @numbers.=sort * .WHAT * Catch blocks * .defined * Unless

It will be fun :)

I however don't understand the reason for the naming of eg elsif, my, slurp/spurt?? (instead of else if or local or fread/fwrite) Is it a perl culture thing? Because they mention in the tutorial that Perl 6 belongs to the C-family languages (and then call the "for" loop in C "loop").

[+] colomon|10 years ago|reply
Let me address your last paragraph and expand a bit on what username223 said. elsif is historical from Perl 5; I think it may be related to the fact that C-style ifs require curly brackets in Perl.

my is Perl 5, is different than local, and is gloriously short. Nicest way I've ever seen to declare a variable. :)

slurp/spurt are routines to read/write an entire file at once. slurp is pretty standard in other languages, I believe, and spurt was chosen to be a natural opposite to it. Perl 6 still has open / close / read / write, etc. Though to be fair, honestly I usually use lines, which (with no other arguments) gives you a lazy list of the lines in standard input / files specified on the command line.

for in Perl 5 was some weird combo which could be iterating over an array or a C-style for. In Perl 6, those have been separated. Because iterating over an array is vastly more common, that gets the shorter keyword. The C-style loop got the loop keyword.

[+] username223|10 years ago|reply
> I however don't understand the reason for naming of eg elsif, my, slurp/spurt??

Yes, it's for historical reasons. "elsif" is spelled that way in Perl 5. Perl 5 has both "my" and "local" to specify lexical and dynamic scoping, respectively, so Perl 6 using "local" for lexical scope would be confusing. "slurp" is a common term for reading the entire contents of a file at once.

[+] imglorp|10 years ago|reply
I am so happy they've included kebab-case identifiers :-) I've always thought they made more sense than camel or snake, because there's no shift key involved. It also brings fond memories of fun in lisp land.
[+] jrumbut|10 years ago|reply
I'm so happy to learn the term kebab-case (and agree that it's very usable and supremely typable)
[+] krylon|10 years ago|reply
I really like the fact that Perl6 has a proper type system.

I like even more that you can mix static and dynamic typing, so to speak. After taking their sweet time, I am not overly confident about adoption of Perl6, but I hope I'm wrong.

At least, from what I can tell so far, Perl6 manages to keep the spirit of Perl, while fixing a number of things that were wrong, or at least problematic, in Perl5.

[+] peteretep|10 years ago|reply
I wish programmers could break away from "tutorials" and "introductions" that are just lists of syntax and keywords.

I want short examples, brief explanations of those, and then some problems to solve.

[+] thalesmello|10 years ago|reply
learnxinyminutes.com solves your problem about how the language works, but doesn't give you problems to work with.
[+] stesch|10 years ago|reply
monthly-salary = daily-rate * working-days

Wow. This will make a few people happy who think underlines and camel case are ugly.

[+] epoch1970|10 years ago|reply
That's a poor example for the documentation to use. In a case like that, kebab notation leads to visual ambiguity when reading code, especially within an expression performing math operations. It becomes harder, at a glance, to tell if the "-" is the kebab connector or if it's subtraction or negation.

Kebab notation makes sense in other contexts, like DOM IDs and CSS class names. It does not make sense in a case like that.

[+] Sharlin|10 years ago|reply
Adding the missing $ sigils will uglify it quite a bit, though.
[+] zimbatm|10 years ago|reply
Does Perl 6 have fundamental features that don't exist in other languages ? Just curious.
[+] perlgeek|10 years ago|reply
I don't know if any of these features are really unique, but the combination of having them all is certainly unique:

* Strings that are made of Unicode grapheme clusters instead of codepoints or bytes. This means that a substr() operation for example can't even accidentally rip a apart a base character and a combining character on top of it

* Grammars as a language feature

* Gradual typing

* A built-in meta object protocol

* Concurrency based on high-level primitives (promises, queues, supplies, ...) with syntactic support (instead of threads and locks; which are still available if necessary, but discouraged, because they don't compose well).

* Lazy lists

[+] awwaiid|10 years ago|reply
[minor syntax/markup edits]

One that has caught my fancy are various uses of the "Whatever Star". This appears as a * in a few contexts. In many it is really a shortcut for the "Whatever" class, so you can use it in function signatures to enter sort of "automatic mode".

  @shuffled_names = @names.pick(*) # randomly pick... however many you have. whatever.
But I think more interesting and different than that is using whatever-star as an automatic lambda thing.

  @nums.map(*/2 + 3)              # expression-lambda from context around a whatever-star
  @nums.map( -> $n { $n/2 + 3 } ) # equivalent with a real stabby arrow lambda
  @nums.map( { $^n/2 + 3 } )      # $^n is a generated alphabetical-positional argument
I suppose this isn't really fundamental... but is definitely different.
[+] doodpants|10 years ago|reply
This guide is gorgeous; the choices made for fonts, styling, and formatting are just perfect. I wish more online documentation looked this good.
[+] lovboat|10 years ago|reply
At first sight I find amusing comparing Ruby to Perl 6. (a=. sort) (a.sort!) (a.what) (a.class) (say a) (puts a) (for @a=>item) (a.each {|item| ..} ) and the similarities, push, shift, splice, ...

I see nothing new here. But I must say that Perl 6 seems to be easier to learn than Perl 5 for beginners.

[+] justinator|10 years ago|reply
This is just a little intro cheat sheet, it's not supposed to be scary - quite the opposite, in fact. Easy things should be easy.

The magic is in the more advanced parts of the language. The, "hard things should be possible" parts.

[+] sigzero|10 years ago|reply
I love that Perl 6 has a proper REPL now.
[+] raiph|10 years ago|reply
A note of caution; it's way better than nothing and will get where it needs to be one day, hopefully in 2016, but it currently uses some awful hacks that make it suck for a lot of stuff.
[+] HeadlessChild|10 years ago|reply
When is Perl 6 going to be a standard installed package for the Linux distributions (Debian, CentOS, Ubuntu)?
[+] perlgeek|10 years ago|reply
I don't think anybody can predict the future well enough to answer that.

Languages become part of the standard installation by having very commonly used toos written in them.

I might be wrong, but I'm pretty sure ruby isn't part of a standard Debian installation, and neither is lua, for example. Ruby is very popular for web apps, but you don't need web apps to boot the computer, start a GUI and install packages, so it's not part of the standard installation.

But it's only an 'apt-get install ruby2.1' or so away, and so is rakudo (the current Perl 6 implementation). The debian package in stable is outdated, but work on newer versions is in progress. (Don't know about CentOS, sorry).

[+] mundanevoice|10 years ago|reply
I am curious, what's the use of learning perl6 in 2015?
[+] krylon|10 years ago|reply
Well, I can tell you what's the use of learning Perl 5 and that I suspect most of it will apply to Perl 6 as well:

Perl, more than any other language I know, sacrifices nearly every other property in the name of being useful. It's not a conceptually clean language, or an elegant one, or a simple one, but if you need to get stuff done, now, there is very little that can compete with it. (At least for some rather specific values of "stuff" - Perl, IMHO, really shines at small-ish scripts that need to convert data from some format to another, or merge data from different sources, especialy when lots of text-handling are involved). Parsing a log file, or matching user accounts from a Windows domain with employee records in an ERP system's database are two examples that come to mind because I had to do those things not too long ago.)

Perl 5 has problems though, especially when it comes to writing large-ish programs. While you can write readable und unreadable code in any language, Perl makes writing unreadable, unmaintainable code easier than, say, Python. Perl 6 tries to fix a lot of this while remaining as useful as Perl 5 (or at least trying to).

[+] wwweston|10 years ago|reply
I don't know Perl 6. But here's the reasons why I've considered dusting off my Perl 5:

- Subjective, but in my experience, the Perl community is more full of smart yet practical people than any other dynamic language community I've participated or dipped my toe in (and most popular static manifestly typed language communities to boot). I don't say this to trash Ruby or Python (or even JavaScript and PHP, which have plenty of smart users and participants); I just mean that I often learn more from engaging with the Perl folks.

- Kindof a corollary, but Perl 5 seems one of the few places where industry's reflexive treadmill dash towards the newly-formed but usually isocapable turned into a careful reflection on using the existing power at hand wisely and the best marginal gains from key additional features.

Place two jobs in front of me, one of them working on a new Go project, the other on a new Perl 5 project, my bet is going to be that the latter would be part of a more satisfying overall experience.

Now, Perl 6, this is starting to look like a language where they are going to make a number of things easy that most programmers didn't even know were hard, a number of things possible that most programmers didn't even know were possible, where recent PL research is going to meet further practicality, where unicode might even actually be reasonably comfortable to work with.

[+] s_kilk|10 years ago|reply
Same use as in learning any other language.

We could very well have asked what was the use in learning Go in 2010, but look how that turned out.

Perl6 is currently a very interesting language with a relatively weak module ecosystem. Which is a position many languages have been in before.

Let's not dismiss it out of hand.

[+] peteretep|10 years ago|reply
If you'd learned Perl5 in 1994, you'd have had twenty years of exceptionally fun employment and community out of it.
[+] arca_vorago|10 years ago|reply
Well I'm not doing it anymore, but I was using bioperl extensively when I was in biotech, but there were some gotchas and it wasn't as fast as it could be. With better concurrency, that certainly could reduce analysis time.

Currently, I am also using a monitoring tool called Argus (http://argus.tcp4me.com/) which is completely written in perl. It doesn't seem super well maintained, but I really like it, so I have been reading through the source and have been thinking about doing something similar in Elixir, but Perl6 would be a perfect update for it.

Perl is largely a sysadmin tool, in that many of us sysadmins are not formally trained in programming, but we often need to get shit done, and perl enables that. When bash, awk, and sed start to falter, we tend to use python and perl, so that's another use case. Simpler syntax and better threading would certainly help with that.