如何在Perl中从命令行读取两个文件?
一个人怎么能做到这一点呢?我知道你必须使用。我已经试过尝试一下,但可能只是因为我在Windows上。如何在Perl中从命令行读取两个文件?,perl,command-line,stdin,Perl,Command Line,Stdin,一个人怎么能做到这一点呢?我知道你必须使用。我已经试过尝试一下,但可能只是因为我在Windows上。#运行方式: # run as: # perl my_script1.pl file1 file2 my ($file1, $file2) = @ARGV; open my $fh1, '<', $file1; open my $fh2, '<', $file2; while (<$fh1>) { ... do something with $_ fro
#运行方式:
# run as:
# perl my_script1.pl file1 file2
my ($file1, $file2) = @ARGV;
open my $fh1, '<', $file1;
open my $fh2, '<', $file2;
while (<$fh1>) {
... do something with $_ from $file1 ...
}
while (<$fh2>) {
... do something with $_ from $file2 ...
}
close $fh1;
close $fh2;
#perl my_script1.pl文件1文件2
my($file1,$file2)=@ARGV;
打开我的$fh1,“您没有说明是否需要以不同的方式处理这些文件。如果没有,那么您可以直接使用
,而无需显式调用打开
while (<>) {
# Process $_
}
while(){
#过程$_
}
会很好的。当它到达第一个文件的末尾时,
将继续读取第二个文件。依此类推,直到没有文件可读取。为什么不使用打开
功能打开文件,然后读取文件?我的程序必须能够从命令行获取文件名。示例:./program.pl file1 file2Doesn不能在Windows上工作,但我非常确信它可以在Linux上工作,谢谢!我很肯定它在Windows上也能工作。你能更具体地说明它是如何工作的吗?在Windows上工作很好。也许你的文件关联被破坏了。