*Getopt::Long [#w339818c]

**普通の使い方 [#yf173c82]
 use Getopt::Long;
 
 $debug;
 GetOptions('debug' => \$debug);
 print "$debug\n";
 print $ARGV[0];

 > ./1.pl --debug 
 1
 > ./1.pl --debug2
 Unknown option: debug2
 > ./1.pl foo
 foo

** 引数を取る [#s1ff38b6]
 use Getopt::Long;
 
 $year;
 $debug;
 GetOptions('year=i' => \$year,
            'debug=s' => \$debug);
 print "$year\n$debug\n";

 > ./1.pl --year 2006 --debug test
 2006
 test

**--nodebugみたいに否定・肯定を判定する [#nd330a75]
 #!/usr/bin/perl
 
 use Getopt::Long;
 
 $debug;
 GetOptions('debug!' => \$debug);
 print "$debug\n";

 > ./1.pl --debug
 1
 > ./1.pl --nodebug
 0

** カウントする [#gef136ab]
 #!/usr/bin/perl
 
 use Getopt::Long;
 
 $debug;
 GetOptions('debug+' => \$debug);
 print "$debug\n";

 > ./1.pl --debug
 1
 > ./1.pl --debug --debug
 2

トップ   編集 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS