Scott Walters > Perl6-Variables > Perl6::Variables



Annotate this POD

Related Modules

View/Report Bugs
Module Version: 0.02_002   Source  


Perl6::Variables - Perl 6 variable syntax for Perl 5


This document describes version 0.02 of Perl6::Variables, yet to be released as version 0.02 as of March 28, 2004.


        use Perl6::Variables;

        sub show { print @_[0], @_[1..$#_], "\n" }

        my %hash  = (a=>1, b=>2, z=>26);
        my @array = (0..10);

        my $arrayref = \@array;
        my $hashref = \%hash;

        show %hash;
        show @array;
        show $hashref;
        show $arrayref;

        show %hash{shift};
        show %hash{a=>'b'};
        show %hash{'a','z'};
        show %hash{qw(a z)};
        show %hash<<a z>>;

        show @array[1];
        show @array[1..3];
        show @array[@array];

        show $hashref{shift};
        show $hashref{a=>'b'};
        show $hashref{'a','z'};
        show $hashref.{qw(a z)};
        show $hashref<<a z>>;
        show $hashref.<<a z>>;

        show $arrayref[1];
        show $arrayref[1..3];
        show $arrayref.[@array];


The Perl6::Variables module lets you try out the new Perl variable access syntax in Perl 5.

That syntax is:

        Access through...       Perl 5          Perl 6
        =================       ======          ======
        Scalar variable         $foo            $foo
        Array variable          $foo[$n]        @foo[$n]
        Hash variable           $foo{$k}        %foo{$k}
        Array reference         $foo->[$n]      $foo[$n] (or $foo.[$n])
        Hash reference          $foo->{$k}      $foo{$k} (or $foo.{$k})
        Code reference          $foo->(@a)      $foo(@a) (or $foo.(@a))
        Array slice             @foo[@ns]       @foo[@ns]
        Hash slice              @foo{@ks}       %foo{@ks}

To avoid confusion with bareword keys that look like function calls, Perl 6 reuses the list quoting construct, <<>>, as a sort of subscript.

        Access through...       Perl 5          Perl 6
        =================       ======          ======
        Hash keyed by func      $foo{bar()}     %foo{bar}
        Hash with const key     $foo{'bar'}     %foo<<bar>>

$foo{shift} no longer means $foo{'shift'} as it did in Perl 5 but instead implies $foo->{shift()} or $foo.{shift()}. This is new as of this proposed XXX version 0.02 and will break large amounts of code.


The module is implemented using Filter::Simple and requires that modules to be installed.


Damian Conway (

Scott Walters ( choked up a %hash<<>> implementation. XXX - Scott is proposing this version.


This module is not designed for serious implementation work.

It uses some very simple heuristics to translate Perl 6 syntax back to Perl 5. It will make mistakes, if you get even moderately tricky inside a subscript. Version 0.01 was only 20 lines long, for crying out loud.

Nevertheless, bug reports are most welcome.


Copyright (c) 2001, Damian Conway. All Rights Reserved. This module is free software. It may be used, redistributed and/or modified under the terms of the Perl Artistic License (see

syntax highlighting: