我有两个目录,一个目录是文件HG111_1_001.txt,另一个目录是HG111_2_001.txt。这两个文件需要通过一组命令(sub single 和 sub double)进行处理,然后作为一对带回 sub playnice。我遇到的问题如下:
代码返回以下模棱两可的警告: Use of uninitialized value $file2 in string at C:\Users\prl\tools.pl 第 52 行。这将是最后的打印行。
启用使用 Carp 时,此错误指示: main::playnice(HG111_2_001.txt 在第 37 行调用和 main::playnice(HG111_1_001.txt 在第 21 行调用
这些是我将值传递给子时对应的行。
#!/usr/bin/perl -w
use strict;
use warnings;
my $dirname = 'C:\Users\prl';
my $dirname2 = 'C:\Users\prl\1';
my $file1;
my $file2;
#Read Directory and find first file
opendir( D, $dirname2 ) or die "can't opendir $dirname: $!";
while ( $file2 = readdir(D) ) {
next unless $file2 =~ m/^HG111_1_0/;
my $path2 = "$dirname2\\$file2";
single( $file2, $path2 );
playnice($file2);
}
#Pass to first sub
sub single {
my $file2 = shift;
my $path2 = shift;
print "$path2\n";
print "$file2\n";
}
opendir( DIR, $dirname ) or die "can't opendir $dirname: $!";
while ( $file1 = readdir(DIR) ) {
next unless $file1 =~ m/^HG111_2_0/;
my $path2 = "$dirname\\$file1";
double( $file1, $path2 );
playnice($file1);
}
sub double {
my $file1 = shift;
my $path1 = shift;
print "$path1\n";
print "$file1\n";
}
sub playnice {
my $file1 = shift;
my $file2 = shift;
print "$file1", "$file2", "\n", 'orked?';
}