-
Notifications
You must be signed in to change notification settings - Fork 0
/
Getopt::Long_involved_parameter.pl
53 lines (45 loc) · 1.05 KB
/
Getopt::Long_involved_parameter.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
advanced usage for Getopt::Long;
if you want to be special at perl command line parameter,you should use array to tranfer your para.
the usage show as below:
use Getopt::Long;
my @array;
GetOptions(
"-al:s" =>\@array
);
open(IN1,"$array[0]") or die $!;
open(IN2,"$array[1]") or die "$!";
open(OUT,">$ARGV[0]"); #
while(<IN1>){
print OUT $_;
}
while(<IN2>){
print OUT $_;
}
close IN1;
close IN2;
close OUT;
##usage:
Getopt::Long_involved_parameter.pl -al 1.txt -al 2.txt result #the "result" parameter was output file,it take by @ARGV
comment:you should know that GetOptions parameter have not occupied the ARGV parameter count,so,when you use @ARGV,you should start with $ARGV[0]
not $ARGV[1] or $ARGV[2].the example show as below:
##
#!/usr/bin/perl -w
use strict;
use warnings;
use Getopt::Long;
my @array;
GetOptions(
"-al:s" => \@array
);
open(IN1,"$array[0]") or die "$!";
open(IN2,"$array[1]") or die "$!";
open(OUT,">$ARGV[0]");
while(<IN1>){
print OUT $_;
}
while(<IN2>){
print OUT $_;
}
close IN1;
close IN2;
close OUT;