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:
Dave Mitchell
Date:
August 2, 2012 05:58
Subject:
Re: [perl #114024] perl mistakenly warns when $] indexes a slice
Message ID:
20120802125844.GB2763@iabyn.com
On Wed, Aug 01, 2012 at 09:54:31PM +0200, Elizabeth Mattijsen wrote:
> > 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  :-)

There's also a context difference in the way the indices are calculated:

    sub f { print wantarray, "\n"; 0 }
    $a[f()] = 1;
    @a[f()] = 1;

which gives

    $ ./perl /tmp/p

    1
    $ 



-- 
You never really learn to swear until you learn to drive.

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