The Filehandle You're Reading From Got Itself Closed Sometime Before Now. Check Your Control Flow.

develooper Front folio | perl.beginners | Postings from Feb 2003

Re: readline() on airtight filehandle FILE

Thread Previous | Thread Next

From:

John West. Krahn

Appointment:

Feb eleven, 2003 06:15

Field of study:

Re: readline() on airtight filehandle FILE

Message ID:

3E490556.C100E32B@acm.org

Nandita Mullapudi wrote: >  > Hi all,  Howdy,  > am using the following script to parse a long list of files. funnily > enough, it works fine when i endeavor a couple sample files, only when i'm > using a long list of files, it comes upward with this error: >  > readline() on closed filehandle FILE at hashing22.pl line 29, <FILE> line > 13 (#1) >     (W closed) The filehandle you're reading from got itself closed > sometime >     before now.  Cheque your logic flow. >  > i dont know what could be causing this- any ideas? >  > here'southward the script: > #!/usr/bin/perl-w > # takes a file where the showtime line specifies query length, puts in ahash > # the seqid and numbers listed, adds up the numbers, divides by qlen > # and give len coverage.  use strict;  > use diagnostics; >  > $out_dir = "post_parsing_len_cov_files"; > mkdir $out_dir, 0777 unless (-due east $out_dir); > $| = 1; >  > $files= "./listofnames2"; >  > open up (FH,"$files") or dice "cannot create list :$!";  The quotes and the parenthesis are not required.  You lot are non trying to "create" the list, you are trying to read a list that has already been created.  open FH, $files or die "cannot open $files:$!";  > while (<FH>) { >  >     push (@listing, $_); > }  Yous need to chomp the lines from the file to get the correct file names.  chomp( my @list = <FH> );  > foreach  (@list) { > $filename=$_;  foreach my $filename ( @list ) {   >     open (FILE, $filename);  You should E'er verify that the file opened correctly.      open FILE, $filename or die "Cannot open $filename: $!";  >     open (HASH_OUT, ">$out_dir/$filename.stats");      open HASH_OUT, ">$out_dir/$filename.stats"         or die "Cannot open $out_dir/$filename.stats: $!";  >     my %hash; > while (<FILE>) > { >     if (/^Query : (.*)\South/1000){  You lot are reading a line at a time from <FILE> so you don't need the /one thousand option.  Are you sure you don't want the terminal not-whitespace included in the capturing parenthesis?   >         $qname = "$ane";  The quotes are not needed.  >         impress HASH_OUT "Query : $qname\north"; >     } > else > { > if (/^qlen = (\d+)/1000){  The /one thousand option is not needed.  >  $qlen = "$i";  The quotes are not needed.  >  impress HASH_OUT "querylen = $qlen\n"; > } > else > {@line = split (/\north/); >  foreach $line (@line){  You are processing the file a line at a time so in that location is no demand for the split() and foreach loop.  > ($cardinal,$value) = split (/:/); > $hash {$key} = $value; > #print " $value"; > @nums = split (" ",$value); > #print "$central: @nums"; >  > $tot = &total(@nums); > $cov = $tot/$qlen * 100 ; > if ($cov >= fifty){ >  print  HASH_OUT "$cardinal : $cov\n"; > }}} > }}} >  > close FILE; >  > sub full { > my $sum; >     foreach (@_){ >         $sum += $_; >     } >     $sum; > } > ------------------------------ > a typical file to be read past this script is would look like this: >  > Query : MAL13P1.227_ubiquitin-conjugatin > qlen = 278 >  > >CpType1H_3652:111 81 > >CpIowa_1214.266:111 121 > >CpGSS_AQ842837:98 > >CpType1H_3631:118 > >CpIowa_1214.272:118 74 26 > >CpIowa_1214.275:77 90 141 17 10 17 > >CpEST_AA390251:117 > >CpEST_AA390240:102 > >CpType1H_3267:77 143 > >CpGSS_AQ842682:98 >  > ---------------------------------- > SOME files besides don't take any lines in them after the kickoff two. > whatsoever suggestions on improving my long winded coding skills (or lack > thereof) are virtually welcome.    #!/usr/bin/perl -westward # takes a file where the offset line specifies query length, puts in ahash # the seqid and numbers listed, adds up the numbers, divides by qlen # and give len coverage.  use strict; use diagnostics;  my $out_dir = 'post_parsing_len_cov_files'; mkdir $out_dir, 0777 unless -east $out_dir;  my $files = 'listofnames2'; open FH, $files or die "Cannot open up $files: $!"; chomp( @ARGV = <FH> );  my $qlen; while ( <> ) {     if ( $. == ane ) {         open HASH_OUT, '>', "$out_dir/$ARGV.stats"             or die "Cannot open $out_dir/$ARGV.stats: $!";         }     next unless /\Southward/;     if ( /^Query : (.*\Southward)/ ) {         impress HASH_OUT "Query : $1\n";         }     elsif ( /^qlen = (\d+)/ ) {         $qlen = $1;         print HASH_OUT "querylen = $qlen\n";         }     elsif ( /^(.+):(.+)/ ) {         my $cov = total( split ' ', $2 ) / $qlen * 100;         if ( $cov >= 50 ) {             impress HASH_OUT "$1 : $cov\due north";             }         }     }  __END__    John --  use Perl; programme fulfillment      
Thread Previous | Thread Side by side
  • readline() on closed filehandle FILE by Nandita Mullapudi
    • Re: readline() on closed filehandle FILE by John Westward. Krahn
    • Re: readline() on closed filehandle FILE past Rob Dixon

bennerhipen1936.blogspot.com

Source: https://www.nntp.perl.org/group/perl.beginners/2003/02/msg41588.html

0 Response to "The Filehandle You're Reading From Got Itself Closed Sometime Before Now. Check Your Control Flow."

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel