develooper Front page | perl.perl5.porters | Postings from September 2010

Re: [perl #77468] Smart match goes wrong with array slice -precedence problem?

Thread Previous
From:
Rafael Garcia-Suarez
Date:
September 7, 2010 07:18
Subject:
Re: [perl #77468] Smart match goes wrong with array slice -precedence problem?
Message ID:
AANLkTim+ROu8c5j3_jTyDOUexy__WZgjFcnBRJu0OScC@mail.gmail.com
On 28 August 2010 23:49, David Leadbeater <dgl@dgl.cx> wrote:
> This reminded me of some odd behaviour I had never had time to investigate.
>
> It's not really a precedence problem, the suggested workaround of adding parens
> doesn't exactly work:
>
>  (1,2,3) ~~ [1..3] # true
>  (3) ~~ [1..3] # true
>  (3,3,1) ~~ [1..3] # false
>
> This is because this compares the last item of the LHS with the array and 3 ~~
> [1..3] is true.
>
> Looking at how smartmatch works underneath it actually takes a reference to the
> array at op generation time (by calling ref_array_or_hash in op.c, B::Deparse
> will show you). This function doesn't seem to take array slices into account.
>
> Patch attached. Although I'm not sure I like the approach of teaching
> ref_array_or_hash to return an anonlist for slices, although it does seem to
> work.

Thanks, applied to bleadperl as 329a333e7a4ed898282bec7f485751efbea92e8f.

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