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

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

Thread Previous | Thread Next
From:
Father Chrysostomos via RT
Date:
August 1, 2012 12:49
Subject:
[perl #114024] perl mistakenly warns when $] indexes a slice
Message ID:
rt-3.6.HEAD-11172-1343850544-23.114024-15-0@perl.org
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] = /(.*)/

-- 

Father Chrysostomos


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

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