名前付きオプションを使う
--verboseのような文字列のオプションを使う場合はGetopt::LongのGetOptionsを使うと簡単です。
use strict;
use warnings;
use v5.10;
use Getopt::Long;
my $file = "data.csv";
my $verbose = '';
GetOptions('verbose' => \$verbose, 'file=s' => \$file) or die;
if ($verbose) {
say "--verboseを指定しました。";
}
printf "ファイル=[%s]\n", $file;
上記のスクリプトの場合--verbose以外に-vや-verboseなどでも--verboseと指定したことと同じになります。それが嫌な場合は下記のようにgnu_getoptを指定して下さい。use Getopt::Long qw(:config gnu_getopt);
