Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: v5.36 syntax error around given/when

by BillKSmith (Monsignor)
on Jun 10, 2022 at 20:22 UTC ( [id://11144668]=note: print w/replies, xml ) Need Help??


in reply to v5.36 syntax error around given/when

I believe that the 'modern way' is to fall back to either a chain of elsif for simple choices such as this:
while ( my ( $k, $v ) = each %opts ) { for ($k) { if (/h/) { ...; } elsif (/v/) { ++$verbose; } elsif (/i/) { $infile = $v; } else { die "*** BUG: no handler for -$k.\n"; } } }

or a 'dispatch table' for more complex switches.

while ( my ( $k, $v ) = each %opts ) { state %dispatch = ( h => sub{...;}, v => sub{ ++$verbose;}, i => sub{ $infile = $v; }, ); die "*** BUG: no handler for -$k.\n" if !exists $dispatch{$k}; &{$dispatch{$k}}; }
Bill

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (4)
As of 2024-04-19 03:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found