perl输入多个文件

perl输入多个文件,perl,input,Perl,Input,可能重复: 我有一个perl脚本,需要在命令行上运行,但也提供三个输入文件和一个输出。我不想做STDIN,因为我正在编写一个包装器脚本,以便对多个文件多次使用perl脚本 所以,我现在有这个: open (FICHIER, "<$file1") || die "file not found"; chomp($file1); @b=<FICHIER>; open (SPECIES, "<$file2"); $species=<SPECIES>; chomp(

可能重复:

我有一个perl脚本,需要在命令行上运行,但也提供三个输入文件和一个输出。我不想做STDIN,因为我正在编写一个包装器脚本,以便对多个文件多次使用perl脚本

所以,我现在有这个:

open (FICHIER, "<$file1") || die "file not found";
chomp($file1);
@b=<FICHIER>;

open (SPECIES, "<$file2");
$species=<SPECIES>;
chomp($species);

open (FILE3, "<$file3>");
$file3 = <FILE3>;
chomp($file3);

open (OUTFILE, ">$outfile");
chomp($outfile);
open(FICHIER,“$outfile”);
chomp($outfile);
我需要这样做:

perl myscript.pl textfile1 textfile2 textfile3 outputfile

我需要$file1代表textfile1,$file2代表textfile2等

提前谢谢


标记

在主程序中,shift函数提取off@ARGV的参数,这是命令行参数列表。所以你可以说:

my $file1 = shift || die "Need 4 file names";
my $file2 = shift || die "Need 4 file names";
my $file3 = shift || die "Need 4 file names";
my $outfile = shift || die "Need 4 file names";
此外,“使用严格”和“使用警告”是良好的做法,这三个论点是开放的:

open my $FICHIER, '<', $file1 or die "$file1 - $!";

打开我的$FICHIER,”在主程序中,一个shift函数提取off@ARGV的参数,这是命令行参数列表。所以你可以说:

my $file1 = shift || die "Need 4 file names";
my $file2 = shift || die "Need 4 file names";
my $file3 = shift || die "Need 4 file names";
my $outfile = shift || die "Need 4 file names";
此外,“使用严格”和“使用警告”是良好的做法,这三个论点是开放的:

open my $FICHIER, '<', $file1 or die "$file1 - $!";
打开我的$FICHIER,'