igotlongestname has asked for the wisdom of the Perl Monks concerning the following question:
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."
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#!/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); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Open in for loop/array structure
by apl (Monsignor) on Jun 02, 2008 at 23:15 UTC | |
|
Re: Open in for loop/array structure
by pc88mxer (Vicar) on Jun 02, 2008 at 23:37 UTC | |
by duff (Parson) on Jun 02, 2008 at 23:45 UTC | |
by pc88mxer (Vicar) on Jun 02, 2008 at 23:47 UTC | |
by ikegami (Patriarch) on Jun 03, 2008 at 00:02 UTC | |
by igotlongestname (Acolyte) on Jun 03, 2008 at 00:29 UTC | |
by ikegami (Patriarch) on Jun 03, 2008 at 00:57 UTC | |
by igotlongestname (Acolyte) on Jun 03, 2008 at 17:56 UTC | |
by ikegami (Patriarch) on Jun 03, 2008 at 20:01 UTC | |
|
Re: Open in for loop/array structure
by jwkrahn (Abbot) on Jun 03, 2008 at 01:50 UTC | |
by igotlongestname (Acolyte) on Jun 03, 2008 at 17:58 UTC | |
by jwkrahn (Abbot) on Jun 03, 2008 at 20:52 UTC |