Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
Keep It Simple, Stupid
 
PerlMonks  

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

by tobyink (Abbot)
on Apr 30, 2012 at 16:40 UTC ( #968108=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Wrong behavior of the implicit smart operator in the given/when blocks
in thread Wrong behavior of the implicit smart operator in the given/when blocks

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'


Comment on Re^3: Wrong behavior of the implicit smart operator in the given/when blocks
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (10)
As of 2014-04-19 08:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (478 votes), past polls