CGI::App to Perl6: Reference handling not needed here

markjugg on 2006-08-26T19:59:15

I'm still wrapping my head around what means that references have been replaced with Capture objects in Perl6.

However, I was pleased to see it means this common idiom is no longer necessary. Often I have a variable that may contain a single scalar value or an arrayref of values.

Perl5:

my @new = (ref $old eq 'ARRAY' ) ? @$old : ($old);
But Perl6 Does The Right Thing, Easily
my @new = @$old;

Perl5 would complain if you tried to deference $old as an array when it wasn't an arrayref.

Now I have look through the CGI::Application code and see all the places I can shave off a few bytes with this refactor...

Here's another case in Perl6 where reference handling is not needed, while Perl5 requires it:

# Perl6 will properly assign @a to the 'k' key,
# without using reference notation. 
my @a = ( 1,2 );
my %h = (
    k => @a,
    j => 'm',
);