TPC Day 3: The Tricks of Perl 6

by Schuyler Erle

Damian Conway commenced his joint presentation with Larry Wall on the state of Perl 6 Wednesday morning at OSCon by giving due thanks to the hundreds of companies and individuals who have supported the design of Perl 6 through financial contributions to the Perl Foundation. Damian then pointedly noted that the title of their presentation was not in fact "Perl 6: Where Is It?" but rather "Perl 6: Where Is It At?"

Where it's at is a place that is markedly different from Perl 5, but it still looks and feels like home. So far, Damian reported, Larry has already laid out the design for all kinds of goodies, including implicit subroutine parameters, higher order functions, a fully object-oriented exception mechanism, a switch statement, a hugely powerful new regexp engine, and a whole raft of new and improved operators. They are still working on, among other things, a new object-orientation model, multiple dispatch, method delgation, multi-dimensional data structs, and much more. "You will walk out of here more excited about Perl than you walked in," Damian assured the crowd of perhaps a couple hundred hackers, "I want to show you some really cool stuff."

And show us he did. I'll spare you all the gory details, since you can read all the latest news in Damian's Synopsis 5, and his earlier articles on and I will share one particularly juicy tidbit though: Variable aliasing. Suppose you have two arrays whose contents you want to swap. In Perl 5, you might try (@a, @b) = (@b, @a), but that won't work, since the right side will flatten and you'll end up with both lists slurped into @a, and nothing in @b. So you're left having to introduce a temporary third list, which sucks. Not so in Perl 6 -- you'll be able to use :=, the new variable binding operator, which aliases the left side to the right, just like *foo = \$bar does in Perl 5. But in Perl 6, you can go one better and swap the contents of both lists by simply asserting (@a, @b) := (@b, @a), and it will just work. How cool is that?

Some of the new things are a little on the weird side. A lot of people seem dubious about the new use of the underscore as the concatenation operator, but Damian noted that "you don't have to like it, you just have to accept it. We tried everything else." I'm also a little leery of the added responsibilities laid on =~, the Perl 5 regexp binding operator. In Perl 6, it will become the catch-call "smart-match" binding operator, and automagically seek some kind of logical match between its right hand and left hand sides by analyzing their respective data types at runtime and doing whatever makes the most sense. Now, this sounds great in theory, but since Perl determines variable type at runtime, this seems like it has the possibility for all kinds of incomprehensible hell to break loose just when it's least expected. Perhaps that's the price to be paid for so much power at your fingertips, which, come to think of it, may not be so different from Perl 5, after all.

Some things really will change, though, like the regexp engine, which is up for a major overhaul. "Never mind that other languages followed Perl 5's lead in regexp languages," Damian observed, "They will follow again!" When all this will come to pass, precisely, is still unclear. Asked about the schedule for the remaining design of Perl 6, Larry inquired, "What is this 'schedule' thing? We have a plan, but we don't have a schedule." Damian added that "it's very important to us that we get it right, and not just 'right now'. We're planning a twenty-year lifetime for this thing, so another year or even two probably won't seem like so much in the long run."