develooper Front page | perl.perl5.porters | Postings from October 2008

Re: Why are "Scalar value better written as" warnings not thrown for arrayrefs?

Thread Previous | Thread Next
From:
Chas. Owens
Date:
October 31, 2008 07:41
Subject:
Re: Why are "Scalar value better written as" warnings not thrown for arrayrefs?
Message ID:
58ce48dc0810310741w5b2fa5b1p68d21b3a722ac047@mail.gmail.com
On Fri, Oct 31, 2008 at 09:13, Rafael Garcia-Suarez
<rgarciasuarez@gmail.com> wrote:
> 2008/10/31 Chas. Owens <chas.owens@gmail.com>:
>> I noticed today that no warning is thrown when a reference is used in
>> a slice of one element, is there a reason for this?  I tested with
>> both 5.8.8 and 5.10.0.
>
> Because in the @a[0] case, the tokenizer is able to see the whole @a
> expression, and check some heuristics to throw the warning, while in
> the @{$ref}[0] case, the parser is called to parse what's in the
> braces.
>
> As many syntax warnings, they're only heuristics.
>
> Example of another way to fool the warning: @a[q/0/].
>
> --
> #11953 Bien sûr, ce n'est qu'une heuristique, ce qui veut dire plus
> prosaïquement que ça ne marche pas.
>

I understand that the parser can't know what is between the braces,
but isn't the fact that it sees @{anything at all}[0] enough to throw
the warning?  Is there a valid "anything at all" that doesn't deserve
the warning?

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

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