I recently got bit by C<return;> in Perl 5, which leads me to wonder
about Perl 6. C<return>, when called without an expression, tries to
DWIM, returning an empty list in list context and undef in scalar
context, which is generally a good thing. But I came across this code
at work this week:

    use CGI qw(:standard);
    
    my $foo = Bar->new(
        name => "Baz",
        value => param('baz'),
        something => 'else'
    );

See the problem? C<param> uses C<return;>. In this example, it's
called in list context. So if there is no 'baz' parameter, the list
will get shifted like so:

    my $foo = Bar->new(
        name => "Baz",
        value => "something",
        else => undef
    );

I can't imagine how much trouble this would have caused me if I didn't
know about the C<return;> special case. Any chance this will work
differently in Perl 6? I'd be tempted to suggest that C<<=>>>, in its
new role as pair constructor, put things in scalar context, but lately
I've started to write join's like so:

    my $string = join "," => @array;

I want my cake. And I want to eat it to, dang it!

-- 
matt

Reply via email to