You are here



Perl 6 for Users and Sysadmins

When he's not busy demystifying RRDtool, Tobi Oetiker is a language evangelist. On Monday afternoon, he brought Perl 6 to the masses. Brian Sebby joked on Twitter: "Perl 6 has a lot of cool features that I'd really like to use. I also felt this way when it was just around the corner at LISA '02." Indeed, Perl 6 has been 11 years in the making, and still hasn't gained much of a foothold in the sysadmin community. Perhaps that's not too surprising, considering how useful Perl 5 remains.

Perl 6 is not just an incremental upgrade, but a full re-imagining of what the language should be. Tobi describes it as "Perl for the people, not Perl for Larry [Wall]". While much remains the same from Perl 5, especially the "there's more than one way to do it" philosophy, much has changed. Huffmanization is a major design consideration, leading to new functions like say, which is similar to print, except shorter and it automatically appends a newline to the end. This effectively saves four keystrokes per line.

Variables get some updated treatment, too. +$variable treats the value as a number, while ~$variable is treated like a string. To use $variable as a boolean, prepend a '?'. Much like Unix's "everything is a file" philosophy, Perl 6 has embraced an "everything is an object" philosophy. So variables now have their own methods. Want to capitalize a string? Try $variable.captialize Variables can even print themselves, like so: $variable.perl.say

Strings are more powerful than in Perl 5. Code can be executed inside a string by using {} or by calling a function with &. This prompted one attendee to ask "when did Perl become Lisp?" Tobi replied with "whatever your favorite language is, you should be able to program it in Perl 6.” In fact, much of Perl 6 is written in Perl 6.

Many new (and old) quoting styles are available for use, with more configuration options to control behavior. Regular expression syntax has changed as well. $/ now contains regexp matches. Match options are moved before the pattern, and capitalization always reverses the metasyntactic meaning of an escaped alphabetic character.

With the everything-is-an-object focus, you'd naturally expect Perl 6 to have features for object-oriented programmers. Classes are easily defined with the 'class' directive, and [single] class inheritance is supported. Classes can pull in functionality from 'roles' by using the 'does' statement.

New data types and even operators can be written in Perl 6 programs. switch-like functionality is made easier with given...when. The syntax of control structures has changed, and if now supports multi-comparison statements (e.g. 3 < $pi < 4 ). subroutines can now take named arguments instead of positional arguments, making functions which have many arguments easier to manage.

Frankly, it was hard to keep up with all of the newness that Perl 6 offers. It's a very interesting language, but will require a lot of work for Perl-5-savvy sysadmins to migrate to. The implementation is still rapidly evolving, which also causes some shyness for operational use. Several of the examples in the session work on an April build of the raduko Perl 6 interpreter, but not on the latest. It's easy to understand why adoption has been slow, but perhaps 2012 will be the year of Perl 6?