Siaris

What is Perl-6?
19 Jul 01 - http://www.siaris.net/index.cgi/Programming/LanguageBits/Perl/20010719.rdoc

If you interact with the Perl community (via usenet or various web-sites) you’ve probably heard about Perl-6 by now. But what exactly is it? Just another step in the versioning scheme or something more? I can’t tell you exactly what Perl-6 will eventually look like, but I can tell you what and why it is.

The change from Perl4 to Perl5 was essentially Larry Wall’s rewrite of Perl, and quite a bit was added to the Perl language at the time (but not much of the Perl4 language was changed). Perl-6 is to be, in Larry’s words: "the community’s rewrite of Perl".

Why rewrite Perl? A primary reason is to rewrite the core of perl (that’s the perl source code, not the Perl language) to make it cleaner, faster, more extensible, and easier for people to understand so that more people can participate in the maintainance and development of perl itself.

Larry also decided that there is no time like the present to investigate changes to the language itself: what sorts of things aren’t working out as well as we hoped, and what sorts of additions would be useful. Thus, the Perl6 RFC process began, and some 361 RFC’s for language changes and/or additions were submitted by the greater Perl community.

Not all of the requests will be integrated into Perl-6 of course, they are there for Larry and the team of Perl-6 developers to sift through and use in the new design. The process will take some time and you shouldn’t expect to see a usable Perl-6 for perhaps another year. However, there are a few changes that are apparent already:

Currently, as I’m sure you well know by now, we have three type symbols for variables: $ for scalars, @ for arrays, and % for hashes. However, you also know that these are symbols not strictly applied to variables, but to the type of thing you want to access. For example, to obtain the scalar value at index 3 of an array you use the $ symbol:

    print $array[3];

In Perl-6 these type symbols will be exclusively used with their variable types, not the data type being accessed — thus, the following will be the correct syntax:

    $scalar = 12;
    @array  = (1,2,3);
    %hash   = (name => 'andrew', beer => 'dark ale');

    @slice  = @array[1,2];
    $scalar = @array[0];

    %hash{'age','children'} = (37, 2);
    print %hash{name};

As you can see, no matter what type of value you access you will use the variable type symbol (no more using @ for slices of hashes, and $ for scalar access of single array or hash elements).

The -> dereference arrow will be replaced with a dot (.). This makes Perl more similar to other OO languages with respect to calling object methods:

    $foo = SomeObject->new();
    $foo->some_method();

    # becomes:

    $foo = SomeObject.new();
    $foo.some_method();

This means that the dot will no longer be used as the concatenation operator — the new concat op will likely be the ~ character.

Yes, you will have the ability to declare variables as certain types (such as ‘int’ or ‘constant’), or dimensioning arrays to a certain size. You won’t be required to do this sort of thing, but it allows perl to optimize the code if you do.

When used in a scalar context, hashes and arrays will return a reference to themselves. This means, to assign a reference to a hash or array we can do the following:

    $a_ref = @array;
    $h_ref = %hash;

But, don’t worry about your habit of getting the length (number of elements) of an array by using it in scalar context, because now, an array reference in numerical context will return its length, and will return true if it holds any elements in a boolean context, so we can still perform the same sorts of array testing as we do now.

As you can see even from this short foray, Perl-6 won’t simply be adding new stuff for us to use, but will be changing some of our currently familiar syntax. This is not a bad thing. The changes proposed so far make a good deal of sense and we should not fear them merely because we will have to make some adjustments to they way we currently do things. Also be aware that there will be some sort of compatibility mode so that Perl-5 programs can still be run (not to mention that versions of Perl-5 will not be disappearing anytime soon either).

There is a good more information about Perl-6, and you can stay abreast of its progress by checking out the following two sites:

    http://www.perl.org/perl6/
    http://dev.perl.org/perl6/

*****