could also be replaced withwhen ( 'h' ) { ... }
if ( $k eq 'h' ) { ...; next }
Makes it more tail-heavy than head-heavy.
In this case, this could be cleaned up by using Getopt::Long.
use Getopt::Long qw( GetOptions ); Getopt::Long::Configure(qw( posix_default )); GetOptions( 'help|h|?' => \&help, 'verbose|v' => \my $verbose, 'force|f' => \my $force, 'table|t=s' => \my $table, ) or usage(); @ARGV == 0 or usage( "Too many arguments" );
Sample help and usage:
use File::Basename qw( basename ); sub help { my $prog = basename( $0 ); print "Usage: $prog [options] $prog --help Options: --verbose -v ... --force -f ... --table {table} -t {table} ... "; exit( 0 ); } sub usage { if ( @_ ) { my ( $msg ) = @_; chomp( $msg ); say STDERR $msg; } my $prog = basename( $0 ); say STDERR "Try '$prog --help' for more information."; exit( 1 ); }
In reply to Re: 'switch' and 'smartmatch' features deprecated in 5.38
by ikegami
in thread 'switch' and 'smartmatch' features deprecated in 5.38
by ibm1620
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |