Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Perl6: same great references, new improved syntax

by blssu (Pilgrim)
on Sep 14, 2002 at 13:42 UTC ( #197861=note: print w/replies, xml ) Need Help??

in reply to Re: Perl6 - value vs. reference issues
in thread Perl6 - value vs. reference issues

Perl 6 still has references -- you can still take an explicit reference like \@array. However, Perl 6 will automatically take a reference or dereference a reference depending on context. Here are a few examples of Perl 6 with the Perl 5 in the comment.

my %x = ( a => 1 ); # same my $y = %x; # $y = \%x %x{a} = 1; # $x{a} = 1 $y{a} = 1; # $y->{a} = 1
This can surprise a Perl 5 veteran because the code $length = @array won't work the same anymore. (This is a good thing for beginning Perl 6 programmers though!)

However, Perl 6 has more contexts than Perl 5 -- numeric and boolean contexts -- so some Perl 5 idioms still work. For example, if (@array) ... still works because the 'if' uses boolean context. $length = @array + 0 works because '+' uses numeric context.

Of course, arrays are now objects, so the simplest way to get the length of an array is @array.length.

For more information about variables in Perl 6 check out Apocalypse 2.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://197861]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2021-10-26 08:43 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (90 votes). Check out past polls.