I am writing a simple script that I want to read in an array of input file names, then loop through each file ... performing some operations and generating an output file for each corresponding input file. I have a script that is "close" to working (at least I believe it's close).
When attempting to execute, the script gets through the first iteration ($k=0, code attached below) just fine, generating the output file "ND_out-02-00.txt", but as it increments to $k=1, I get the following error:
"print() on closed filehandle OUT at isotopes-p7.perl line 17, <GEN0> line 46079.
Use of uninitialized value in scalar chomp at isotopes-p7.perl line 19, <GEN0> line 46079.
Use of uninitialized value in concatenation (.) or string at isotopes-p7.perl line 20, <GEN0> line 46079.
Can't read the source:No such file or directory at isotopes-p7.perl line 20, <GEN0> line 46079."
#!/usr/local/bin/perl -w
use IO::File;
my $file = IO::File->new;
@FN=("out-02-00.txt","out-02-01.txt","out-02-02.txt","out-02-03.txt","
+out-02-04.txt","out-02-05.txt","out-02-06.txt","out-02-07.txt","out-0
+2-08.txt","out-02-09.txt",
"out-02-10.txt","out-02-11.txt","out-02-12.txt","out-02-13.txt",
+"out-02-14.txt","out-02-15.txt","out-02-16.txt","out-02-17.txt","out-
+02-18.txt",
"out-02-20.txt","out-02-21.txt","out-02-22.txt","out-02-23.txt",
+"out-02-24.txt","out-02-25.txt","out-02-26.txt","out-02-27.txt","out-
+02-28.txt",
"out-02-30.txt","out-02-31.txt","out-02-32.txt","out-02-33.txt",
+"out-02-34.txt","out-02-35.txt","out-02-36.txt","out-02-37.txt","out-
+02-38.txt");
$FN=@FN;
for($j=0; $j<$FN; $j++){
print "$FN[$j]\n";
}
for($k=0; $k<$FN; $k++){
print "$FN[$k]\n";
$filename = <$FN[$k]>;
chomp ($filename);
$file->open("< $filename") or die("Can't read the source:$!");
open(OUT, ">ND_$filename");
select (OUT);
@BU=();
@MA1=();
@MA2=();
until ($file->eof) {
my $line = $file->getline();
if ($line =~ /K-INF,LEAK \(B2/) {
my @col3 = split(qr/\s+/s, $line); #split on whitespace
push(@BU,"$col3[14]");
}
elsif($line =~ /0 EID: 93237/) {
$line = $file->getline();
chomp($line);
@col1 = split(qr/\s+/s, $line);
push(@MA1,"$col1[3] $col1[4] $col1[5] $col1[6] $col1[7] $col
+1[8] $col1[9] $col1[10] $col1[11]");
}
elsif ($line =~ /0 EID: 95241/) {
$line = $file->getline();
chomp($line);
@col2 = split(qr/\s+/s, $line);
push(@MA2,"$col2[3] $col2[4] $col2[5] $col2[6] $col2[7] $col
+2[8] $col2[9]");
}
} # end of until
for($i=1; $i<=58; $i++){
print "$BU[$i-1] $MA1[$i-1] $MA2[$i-1]\n";
}
close(OUT);
}
I know the file names are correct, and in the directory and that they are being accessed in that name sequence since my first for loop simply tests that the names are as expected. I think my problem may be the recursive open/close statements for either the input or output files (or both). Anybody know what's going on here? Thanks!
~Jack
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.