develooper Front page | perl.perl5.porters | Postings from September 2013

[perl #88200] Warning with @ name [0], but none with @ $evaluated [0]

Thread Previous | Thread Next
From:
Father Chrysostomos via RT
Date:
September 14, 2013 01:21
Subject:
[perl #88200] Warning with @ name [0], but none with @ $evaluated [0]
Message ID:
rt-3.6.HEAD-1873-1379121650-227.88200-15-0@perl.org
On Thu Oct 11 17:27:37 2012, jkeenan wrote:
> On Sun Apr 10 08:57:21 2011, blaiseroth@gmail.com wrote:
> > Subject: Warning with @ name [0], but none with @ $evaluated [0]
> > Message-Id: <5.12.1_6652_1302450333@home>
> > Reply-To: blaizer@cpan.org
> > To: perlbug@perl.org
> > 
> > 
> > This is a bug report for perl from blaizer@cpan.org,
> > generated with the help of perlbug 1.39 running under perl 5.12.1.
> > 
> > 
> > -----------------------------------------------------------------
> > [Please describe your issue here]
> > 
> > When you do anything of the form @ name [0] in any context, you get
> > the
> > warning:
> > 
> > Scalar value @ name [0] better written as $ name [0]
> > 
> > as expected. When you do anything in the form of @ $evalulated [0] in
> > any
> > context, though, you get no warning.
> > 
> > Even if the scalar gets evaluated to an object with an overloaded @{},
> > I'd
> > say the warning is still valid. There *should* be no reason you
> > shouldn't
> > always get this warning when doing @ ... [n].
> > 
> > I'm on Windows, but I have confirmation that this is the same on other
> > systems as well as up to Perl v5.13.11.
> > 
> 
> I believe this illustrates what the OP was speaking about:
> 
> $ perl -wE '@name=(qw|alpha beta gamma|);say
> @name[0];$evaluated=[@name];say @{$evaluated}[0];'
> Scalar value @name[0] better written as $name[0] at -e line 1.
> alpha
> alpha

I am inclined to reject this as not-a-bug.  @name[0] is a perfectly
well-defined Perl construct.  I believe the warning exists mainly to
help out newbies who confuse @_[0] and $_[0].  Any newbie who uses
@array[0] regularly (and turns on warnings) is going to see the warning
enough times to get out of the habit.  That it does not always occur
should not matter so much.

This warning can very easily produce false positives.  I would be
against tweaking it to occur more often.

-- 

Father Chrysostomos


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

Thread Previous | Thread Next


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