redtower
1/13/2011 - 3:00 PM

複数の値を取るオプションを扱う

複数の値を取るオプションを扱う

$ perl getopts.pl --opt abc --opt xyz
abc
xyz
$ perl getopts.pl --opt abc xyz
abc
xyz
$ perl getopts.pl
$ perl getopts.pl --opt abc
abc
#!/usr/bin/env perl

use strict;
use warnings;
use Getopt::Long;

my @opt;
GetOptions("opt=s{,}" => \@opt);

foreach my $val ( @opt ){
    print $val . "\n";
}