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

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

Thread Previous | Thread Next
From:
David Leadbeater
Date:
August 28, 2010 14:49
Subject:
Re: [perl #77468] Smart match goes wrong with array slice -precedence problem?
Message ID:
20100828214943.GA32491@babylon.otherwize.co.uk
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.

David

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