Perl 传递参数写法

1 类似着这样的写法

#!/usr/bin/perl -w
use strict;
use warnings;

my $usage=<<USAGE;
Usage:
    perl $0 inputfile
USAGE
if(@ARGV==0){die $usage};

my $file=$ARGV[0];

2 类似这样的写法

#!/usr/bin/perl -w
use strict;
use warnings;
use Getopt::Long;
use POSIX;


my ($input,$output_dir,$seq_num,$file_num,$help,@libfiles);
GetOptions(
    "i:s" => \$input,
    "o:s" => \$output_dir,
    "n:i" => \$seq_num,
    "m:i" => \$file_num,
    "h:s" => \$help,
    "library=s" => \@libfiles
);

die `pod2text $0` if ((!$input) or (!$output_dir));

#帮助文档
=head1 Description

    This script is used to split fasta file, which is too large with thousangs of sequences;

=head1 Usage

    $0 -i <input> -o <outpu_dir> [-n <seq_num_per_file>] [-m <output_file_num>] -h --library lib/stdlib --library lib/extlib

=head1 Parameters

    -i  [str]   Input raw fasta file
    -o  [str]   Output file to which directory
    -n  [int]   Sequence number perl file, alternate chose paramerter 
    -m  [int]   Output file number (default:100)
    -h  [str]   Help manual
    --library   [dir]   Directory with multiple values

=cut

# !     代表否定
# s 代表字符串
# i     代表整型
# f     代表浮点数
#--library 用于传多个参数


print $input,"\n";
print $output_dir,"\n";
print $seq_num,"\n";
print $file_num,"\n";
@libfiles = split(/,/,join(',',@libfiles));
for my $i (0..$#libfiles){
    print $libfiles[$i],"\n";
}

参考:
perl进阶笔记
perlcoc

此条目发表在Perl分类目录。将固定链接加入收藏夹。

发表评论

邮箱地址不会被公开。 必填项已用*标注

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax

Protected with IP Blacklist CloudIP Blacklist Cloud