开发者

perl input multiple files [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

How can I pass command-line arguments to a Perl program?

I have a perl script that I need to run on the command line but also provide three input files and one output. I dont want to do a STDIN as I am writing a wrapper script to use the perl scrip开发者_如何学Ct multiple times for multiple files.

So, I have this now:

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);

I need to do something like this:

perl myscript.pl textfile1 textfile2 textfile3 outputfile

I need $file1 to represent textfile1, $file2 for textfile2 etc.

Thanks in advance

Mark


In the main program a shift function pulls arguments of off @ARGV, which is the list of command line parameters. So you could say:

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";

Also, "use strict;" and "use warnings;" is good practice, and the three argument open::

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜