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

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

Thread Previous | Thread Next
From:
Elizabeth Mattijsen
Date:
August 1, 2012 12:57
Subject:
Re: [perl #114024] perl mistakenly warns when $] indexes a slice
Message ID:
515F2D7F-FA46-4BC0-9FC9-959CF8FDFFE9@dijkmat.nl
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.


Liz
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