Front page | perl.perl5.porters |
Postings from May 2012
[perl #2723] inconsistent warnings
From:
Father Chrysostomos via RT
Date:
May 5, 2012 11:40
Subject:
[perl #2723] inconsistent warnings
Message ID:
rt-3.6.HEAD-4610-1336243205-1910.2723-15-0@perl.org
On Sat May 05 05:30:43 2012, Hugmeir wrote:
> On Wed Jan 11 13:24:59 2012, sprout wrote:
> > On Tue Nov 22 19:50:15 2011, jkeenan wrote:
> > > On Tue Jul 15 20:01:14 2003, tchrist@chthon.perl.com wrote:
> > > > >You're warned about the first part, anyway. Not sure why its
> > > > ambiguous.
> > > >
> > > > >$ perl5.8.1 -wle 'print "I have ", ${int}, " warning.\n";
> $int=1;
> > > > $name<SNIP>
> > > > >Ambiguous use of ${int} resolved to $int at -e line 1.
> > > >
> > > > Because ${int} means ${"int"} not ${int()}, nearly.
> > > >
> > >
> > > Are there any issues remaining in this ticket?
> >
> > Yes, it’s this inconsistency:
> >
> > $ perl5.15.6 -le 'use warnings "ambiguous"; $name{int}'
> > $ perl5.15.6 -le 'use warnings "ambiguous"; ${int}'
> > Ambiguous use of ${int} resolved to $int at -e line 1.
> >
> > I think that ambiguous warning should be extirpated. There is no
> > ambiguity there. ${...} always implicitly quotes a single bareword
> with
> > no + or ; or () ornamenting it.
> >
>
> I'm not entirely convinced about removing the warning, at least not
> entirely. The ambiguity seems more in the intent of the code, rather
> than the parsing. For example:
>
> use warnings 'ambiguous';
> sub etc () {'$fred'}
> ${etc} = 1;
>
> On the other hand, I can't think of any other case where the warning
> would be useful. And making it warn because the bareword is a keyword
> seems useless to me.
> Plus, it's not even self-consistent! ${time[0]} will warn, but
> ${some_sub[0]} won't.
Well, you are changing subject slightly by putting brackets inside the
braces. That bizarre syntax is, well, bizarre--and inconsistent in the
way it is parsed:
${sub{0}} # same as ${ +sub { 0; } }
${time{0}} # same as $time{"0"} or (\%time)->{"0"}
> I'm attaching three patches; The first one disables the ${%s} warning
> when %s is a keyword, so that it only triggers for subs. The second
> disables the ${%s[...]} and ${%s{...}} warnings when %s is a keyword,
> and make it warn when %s is a sub.
The example above suggests that a warning might still be apposite for
this syntax.
> The third removes the two warnings
> altogether.
It looks as though we need a fourth option....
--
Father Chrysostomos
---
via perlbug: queue: perl5 status: open
https://rt.perl.org:443/rt3/Ticket/Display.html?id=2723
-
[perl #2723] inconsistent warnings
by Father Chrysostomos via RT