Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
laziness, impatience, and hubris
 
PerlMonks  

Re: Wrong behavior of the implicit smart operator in the given/when blocks

by educated_foo (Vicar)
on Apr 30, 2012 at 15:35 UTC ( #968099=note: print w/ replies, xml ) Need Help??


in reply to Wrong behavior of the implicit smart operator in the given/when blocks

Smart match and given/when are horribly complex and confusing (see "Smart matching in detail" in perlsyn), with the semantics changing between versions. AFAICT they may even change again in some future Perl, as many people on perl5-porters think they're broken. I'd just stick to "exists $hash{a}", which is not much more to type, and works.


Comment on Re: Wrong behavior of the implicit smart operator in the given/when blocks
Re^2: Wrong behavior of the implicit smart operator in the given/when blocks
by ikegami (Pope) on Apr 30, 2012 at 15:45 UTC

    Specifically, they think the interface is some combination of too confusing, too complex, too error prone. Smart::Match is seen as way better interface.

      As I understand it, it's DOY's smartmatch which is the possible candidate for future Perls. This pushes the behaviour of smart match out to modules (on a lexically scoped basis). So you can:

      use smartmatch 'acme';

      And then the ~~ operator will start acting along the lines of whatever's defined in the smartmatch::engine::acme module. Perl will then come bundled with a backwards compatible behaviour (modelled on 5.14 most probably) and a simplified one.

      Personally, I tend to follow the rule of keeping the left hand side of the smart match as either a non-reference scalar or a blessed object. If you stick to that, then whatever you put on the right hand side, smart match generally behaves pretty sanely and intuitively. (With the possible exception of when you've got hashref on the right hand side - I'm not sure there's any completely intuitive behaviour in that case, but the current behaviour certainly seems no worse than anything else.)

      perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://968099]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2014-04-19 23:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (485 votes), past polls