in reply to 'switch' and 'smartmatch' features deprecated in 5.38

This is a little more concise, I guess:

$opts{h} and HELP_MESSAGE(); $opts{v} and ++$verbose; $opts{f} and ++$force; $opts{t} and $table = $opts{t}; die "*** BUG: no handler for -$_.\n" for grep !/^[hvft]$/, keys %opts;

Replies are listed 'Best First'.
Re^2: 'switch' and 'smartmatch' features deprecated in 5.38
by GrandFather (Saint) on Jun 26, 2023 at 23:29 UTC

    shouldn't each of $opts{...} and be prefixed with exists?

    Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond

      Only the "$opts{t} and $table = $opts{t};" line as the rest rely on a true value.

        If the table is a database table or something, then you'd only ever want it to be a true value anyway. I guess there's the pathological case where you have a database table called "0", which I think is legal in SQL, even if it requires some quoting.

Re^2: 'switch' and 'smartmatch' features deprecated in 5.38
by ibm1620 (Hermit) on Jun 28, 2023 at 01:45 UTC
    I guess for sheer conciseness this would work:
    for ( keys %opts ) { /h/ ? HELP_MESSAGE() : /v/ ? ++$verbose : /f/ ? ++$force : /t/ ? $table = $opts{$_} : die "*** BUG: no handler for -$_.\n"; }

      Although one should first check the keys are all single letter for this case, otherwise one will get matches for words like haft, vatful and thrive.

        %opts was populated by Getopt::Std, so the keys are guaranteed to be one character.
Re^2: 'switch' and 'smartmatch' features deprecated in 5.38
by ibm1620 (Hermit) on Jun 26, 2023 at 13:38 UTC
    I like how that eliminates looping.