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

[perl #119547] 42->{42} works in strict mode

Thread Previous
From:
Father Chrysostomos via RT
Date:
August 31, 2013 20:41
Subject:
[perl #119547] 42->{42} works in strict mode
Message ID:
rt-3.6.HEAD-1873-1377981648-1552.119547-15-0@perl.org
On Sat Aug 31 12:24:23 2013, doy@tozt.net wrote:
> On Sat, Aug 31, 2013 at 12:12:16PM -0700, GlitchMr wrote:
> > Following code doesn't fail, when it should (42 is symbolic ref)
> > 
> >     use strict;
> >     42->{42};
> > 
> > This code also doesn't fail.
> > 
> >     use strict;
> >     sub CONSTANT() { 42 }
> >     CONSTANT->{42};
> > 
> > But this does correctly fail.
> > 
> >     use strict;
> >     sub { 42 }->()->{42};
> >     # Can't use string ("42") as a HASH ref while "strict refs" in
> >     use...
> 
> This bug appears to have been present for quite some time (if not
> forever):
> 
>   $ perl -le'print $]'
>   5.006002
>   $ perl -le'*{"42"} = {foo => "bar"}; use strict; print 42->{foo}'
>   bar
>   $ perl -le'*{"42"} = {foo => "bar"}; use strict; print "42"->{foo}'
>   bar
>   $ perl -le'*{"42a"} = {foo => "bar"}; use strict; print "42a"->{foo}'
>   bar
>   $ perl -le'*{"a"} = {foo => "bar"}; use strict; print "a"->{foo}'
>   Global symbol "%a" requires explicit package name at -e line 1.
>   Execution of -e aborted due to compilation errors.

As currently implemented, "a"->{foo} is subject to strict vars, not refs.

The parser loses the distinction between "a" and the ‘a’ in $a very
early on (they both compile down to const ops).  This is very
longstanding behaviour.  Do we want to change it?  I have sometimes used
INC->{...} instead of $INC{...}, though probably only in one-liners.

-- 

Father Chrysostomos


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

Thread Previous


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