1 つのディレクトリにファイル HG111_1_001.txt、もう 1 つのディレクトリに HG111_2_001.txt という 2 つのディレクトリがあります。この 2 つのファイルは、一連のコマンド (サブ シングルとサブ ダブル) を介して処理し、ペアとしてサブ playnice に戻す必要があります。私が抱えている問題は次のとおりです。
このコードは、次のあいまいな警告を返します: Use of uninitialized value $file2 in string at C:\Users\prl\tools.pl line 52. これが最後の印刷行になります。
Carp の使用が有効になっている場合、このエラーは次のことを示します:
これらは、値をサブルーチンに渡すときに対応する行です。
#!/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?';
}