in reply to Re: v5.36 syntax error around given/when
in thread v5.36 syntax error around given/when
I made the following changes:
I couldn't see any reason to pass $k into the sub; also, made use of sub signature.#!/usr/bin/env perl use v5.36; no warnings 'experimental::for_list'; use Getopt::Std; my %opts; getopts( 'hvi:', \%opts ) or die "getopts failed\n"; my $verbose; my $infile; for my ( $k, $v ) ( %opts ) { state $dispatch = { h => sub { say 'HELP!'; exit }, v => sub { ++$verbose; }, i => sub ($file) { $infile = $file; }, }; my $code = $dispatch->{$k} or die "*** BUG: no handler for -$k.\n"; $code->( $v ); } say "infile = ", $infile // 'undefined';
|
|---|