Matt Diephouse skribis 2004-08-19  9:35 (-0400):
> 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'
>     );

Ouch. You have foo-bar-baz code *at work*? :)

> See the problem?

Yes, you forgot "scalar". param() is *documented* to behave differently in
list context. It's not an unfortunate side-effect, but the official,
documented API.

In fact, this was anticipated and the doesn't-exist case is explicitly
documented as:

    If the parameter does not exist at all, then param() will return
    undef in a scalar context, and the empty list in a list context.

> I can't imagine how much trouble this would have caused me if I didn't
> know about the C<return;> special case.

There is no need to know about the special case, because you can read
exactly how it works in the documentation.

The bare return is there only to avoid a warning. param's behaviour
wouldn't be different with only the second return statement:

    return wantarray ? @{$self->{$name}} : $self->{$name}->[0];

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

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

It's a 180, but it'll workforme.


Juerd

Reply via email to