develooper Front page | perl.perl5.porters | Postings from January 2012

[perl #32083] Warning about scalar @a[$b] triggered in list context

From:
Father Chrysostomos via RT
Date:
January 19, 2012 23:11
Subject:
[perl #32083] Warning about scalar @a[$b] triggered in list context
Message ID:
rt-3.6.HEAD-14510-1327043473-364.32083-15-0@perl.org
On Thu Oct 21 19:16:41 2004, chip wrote:
> The warning about @a[$b] being better written as $a[$b] is triggering
> even in list context, which is wrong.
> 
>     $ perl -wle 'my ($a) = @ARGV[0]'
>     Scalar value @ARGV[0] better written as $ARGV[0] at -e line 1.
> 
> It's quite plausible to have a one-element array slice if you're
> planning on extending the slice later.  Consider a POE sub arg list:
> 
>     sub state {
>         my ($self) = @_[OBJECT];
>         # ...
>     }
> 
> You wouldn't want to make that a $, because if you added another
> subscript, the slice would silently fail:
> 
>     sub state {
>         my ($self, $arg) = $_[OBJECT, ARG0];   # OOPS BUG HERE
>         # ...
>     }

This is one of my pet peeves.  It’s the bareword it shouldn’t be warning
about.  Whether it should warn for @_[0] in list context is slightly
more debatable.

-- 

Father Chrysostomos


---
via perlbug:  queue: perl5 status: open
https://rt.perl.org:443/rt3/Ticket/Display.html?id=32083



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About