[ Perl ] Getopt 使用模板


https://www.cnblogs.com/yeungchie/

  • code
#!/usr/bin/perl -w
use strict;
use Getopt::Long;                  # 声明使用模块

my ($input,$output,$help);

                                   # 定义输入参数
GetOptions (
    "i|input:s"  => \$input,       # 使用 |  表明可以使用 i 或者 input 来表示这个参数
    "o|output:s" => \$output,      # 使用 : 表明输入数据类型
    "h|help"     => \$help,        # 使用 => 来将参数转递给变量
);

die "Usage: Print help message \n" if (defined $help);

open IN,"<$input";
while (){
    chomp;
    print "$_\n";
}
close IN;