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
David Leadbeater
August 28, 2010 14:49
Re: [perl #77468] Smart match goes wrong with array slice -precedence problem?
Message ID:
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


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