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

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

by Tommy (Chaplain)
on Jan 05, 2014 at 21:15 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1069420]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-03-29 00:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found