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

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

Thread Previous | Thread Next
Elizabeth Mattijsen
August 1, 2012 12:54
Re: [perl #114024] perl mistakenly warns when $] indexes a slice
Message ID:
On Aug 1, 2012, at 7:59 PM, Nicholas Clark 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.

Then maybe it should be.  :-)

Seriously, from Perl trainers I've always understood that it is always the most difficult thing for newbies to grasp.  Which is why Larry decided to stick with the sigil for the type of data structure, regardless of the access / context.

> 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")

And some of them you can't even express in writing.  "You say potato, and I say potato".  Gotcha.

>> 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.

Wow, that's pretty obscure.  I guess you *could* argue that that's a bug, but I won't  :-)


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About