in reply to v5.36 syntax error around given/when
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}}; }
|
|---|