Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Journal of markjugg (792)

Saturday August 26, 2006
02:59 PM

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

[ #30762 ]
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.


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',

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.