Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Smart Match is not recursive in 5.10

by szabgab (Priest)
on Dec 22, 2007 at 11:43 UTC ( [id://658640]=perlquestion: print w/replies, xml ) Need Help??

szabgab has asked for the wisdom of the Perl Monks concerning the following question:

I am not sure it should be but I just found that
42 ~~ [23, 17, "42x", 70]
will give you a warning
Argument "42x" isn't numeric in smart match
It is the described behavior as this is Num ~~ Array case but I wonder why it is doing == and not smart matching on each individual element of the Array?

Update

Since then I had another issue with smart matching: "42" ~~ "42.0" is false in 5.10 and I have written a few blog entries too about Smart Matching and Switching in Perl 5.10. If someone is interested...

Replies are listed 'Best First'.
Re: Smart Match is not recursive in 5.10
by polettix (Vicar) on Dec 22, 2007 at 12:33 UTC
    While I don't know why (efficiency, I presume, or simplicity, or simply nobody tought about it, or whatever), I was thinking that recursively applying the smart match on each individual element would allow smart-matching over a "complicated" data structure, like a matrix. Something like:
    42 ~~ [ [ 0 .. 9 ], [ 20 .. 29 ], [ 40 .. 49 ], ]
    I'm still wondering if this could be named a feature or a bug, anyway :D

    Hey! Up to Dec 16, 2007 I was named frodo72, take note of the change! Flavio
    perl -ple'$_=reverse' <<<ti.xittelop@oivalf

    Io ho capito... ma tu che hai detto?
Re: Smart Match is not recursive in 5.10
by mikfire (Deacon) on Dec 24, 2007 at 14:38 UTC
    When did you build? How did you generate this error? I am trying it like this:
    perl -E 'say 42 ~~ [23,17,"42x",70]'
    and generating no error. It actually returns true, like I would expect.
      It's a warning, not an error. Try it with warnings enabled.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://658640]
Approved by FunkyMonk
Front-paged by grinder
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2025-07-09 10:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.