open IN1,"cat $DATA_DIR/$INFILE_NAME |" or die "Can't open $INFILE_NAM
+E: $!\n";
do
open my $in1FH, q{<}, $DATA_DIR/$INFILE_NAME
or die qq{Can't open $INFILE_NAME: $!\n};
As you suspected, you are not reading the numbers file correctly. From your original post it looks like you have 5000 or so numbers in a file, one per line. If you assign the readline into an array rather than a scalar then the whole file is read into the array, one line per element. Furthermore, chomping an array will remove the line terminator from every element in the array. You could read the file line by line in a while loop instead if you like but then you would have to push each line onto the array. These two bits of code are equivalent. Using a loop
my @numbers = ();
while( <$in1FH> )
{
chomp;
push @numbers, $_;
}
Reading directly into an array.
chomp( my @numbers = <$in1FH> );
You have removed the bare code block around the reading of the second file. It was there so that the local $/ ... really was localised to that scope to avoid possible side effects later in your script. Since you have a lot of files to read you could perhaps do something like
my @filesToRead = ( populate this list somehow );
...
foreach my $file ( @filesToRead )
{
open my $in2FH, q{<}, $file
or die qq{Can't open $file: $!\n};
local $/ = qq{</DU>\n};
while( <$in2FH> )
{
...
}
close $in2FH or die qq{Can't close $file: $!\n};
}
I hope this is helpful.
Cheers, JohnGG |