Dear monks,

I'm playing with perl-5.38.0-RC2 and my given / when statements are all receiving deprecation warnings. As explained in the perldelta :

The "switch" feature and the smartmatch operator, ~~, were introduced in v5.10. Their behavior was significantly changed in v5.10.1. When the "experiment" system was added in v5.18.0, switch and smartmatch were retroactively declared experimental. Over the years, proposals to fix or supplement the features have come and gone.

In v5.38.0, we are declaring the experiment a failure. Some future system may take the conceptual place of smartmatch, but it has not yet been designed or built.

These features will be entirely removed from perl in v5.42.0.

I use feature 'switch' and given / when in my program template for processing Getopt::Std options, which means it's everywhere.

#!/usr/bin/env perl use v5.36; use Getopt::Std; use feature qw/switch/; no warnings q/experimental::for_list/; sub HELP_MESSAGE { ...; exit } my $verbose; my $force; my $table; my %opts; HELP_MESSAGE() if !getopts( 'hvft:', \%opts ); for my ( $k, $v ) (%opts) { given ($k) { when ('h') { HELP_MESSAGE(); } when ('v') { ++$verbose; } when ('f') { ++$force; } when ('t') { $table = $v; } default { die "*** BUG: no handler for -$k.\n"; } } }
It looks like I can safely replace "given" with "for" to bind the topic variable. The "when" statement provided a concise way to test the topic, but since that's going away, is this the most concise way to write it?
for my ( $k, $v ) (%opts) { if ( $k eq 'h' ) { HELP_MESSAGE(); } elsif ( $k eq 'v') { ++$verbose; } elsif ( $k eq 'f') { ++$force; } elsif ( $k eq 't') { $table = $v; } else { die "*** BUG: no handler for -$k.\n"; } }
Thanks!

In reply to 'switch' and 'smartmatch' features deprecated in 5.38 by ibm1620

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.