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

[perl #114024] perl mistakenly warns when $] indexes a slice

Thread Previous
From:
Father Chrysostomos via RT
Date:
August 1, 2012 20:21
Subject:
[perl #114024] perl mistakenly warns when $] indexes a slice
Message ID:
rt-3.6.HEAD-11172-1343877695-1998.114024-15-0@perl.org
On Wed Aug 01 12:57:59 2012, elizabeth wrote:
> On Aug 1, 2012, at 9:49 PM, Father Chrysostomos via RT wrote:
> > On Wed Aug 01 10:59:45 2012, nicholas wrote:
> >> On Wed, Aug 01, 2012 at 09:31:03AM +0200, Elizabeth Mattijsen
> wrote:
> >>> I wonder whether this warning shouldn't be removed on the grounds
> >> that:
> >>>
> >>> 1. it is valid Perl 6 syntax, so what are we teaching newbies
> >> anyway?
> >>
> >> But it means something subtly different - there it's a regular
> lookup,
> >> here
> >> it's a trivial slice. Although I'm not sure how often the
> difference
> >> matters.
> >>
> >> I don't think we should use "it's legal Perl 6 syntax" alone as
> >> grounds for
> >> changing Perl 5 behaviour. For example, the analogous hash lookup
> >> syntax
> >> %h{"k"} isn't legal Perl 5.
> >>
> >> I think that the George Bernard Shaw quote "England and America are
> >> two
> >> countries separated by a common language." applies to Perl 5 and
> Perl
> >> 6,
> >> but I'm not quite sure how to paraphrase it. In that there are
> massive
> >> amount of similarities between the two, but you need to treat them
> as
> >> different, else you get into embarrassing mistakes. (eg "rubber")
> >>
> >>> 2. there is only a performance difference between $a[0] and @a[0],
> >> or am I missing something there?
> >>
> >> With a little bit of experimenting I did manage to find one
> >> difference:
> >>
> >> $ perl -le 'sub foo (\[$@]) {}; foo $a[0]'
> >> $ perl -le 'sub foo (\[$@]) {}; foo @a[0]'
> >> Type of arg 1 to main::foo must be one of [$@] (not array slice) at
> -e
> >> line 1, at EOF
> >> Execution of -e aborted due to compilation errors.
> >> $
> >
> > The most significant different is, of course, assignment thereto.
> It
> > changes the context of the RHS.  It is actually useful though, which
> is
> > probably why I usually find myself turning off syntax warnings:
> >
> > @_[0] = /(.*)/
> 
> Aw, evil!  But yes, an idiom that would probably be much more
> prevalent than the prototype issue.

... were it not for the silly warning!


-- 

Father Chrysostomos


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

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