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

Re^6: perldelta unclear on 'given's fate

by Tommy (Chaplain)
on Jan 05, 2014 at 21:15 UTC ( #1069420=note: print w/replies, xml ) Need Help??


in reply to Re^5: perldelta unclear on 'given's fate
in thread perldelta unclear on 'given's fate

I actually think that's pretty cool, despite my desire to see a native switch. I have often use hash constructs to accomplish switch-like behavior, and I think that the for ( $var ) ... approach is much nicer...

# Example of the hash-construct "switch", which is limited and has no +"default". # The output of this code is "abc" use Moo; my $val = 'c'; my @args = qw( abc ); my $obj = __PACKAGE__->new(); { a => sub { say 'a' }, b => \&b, c => sub { $obj->c( @_ ) }, }->{ $val }->( @args ); sub b { say 'b' }; sub c { shift; say for @_ };

Tommy
A mistake can be valuable or costly, depending on how faithfully you pursue correction

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2021-01-27 22:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?