in reply to readline on closed filehandle error

I condensed your script down to the offending part. It still needs some work, but the readline warning disappeared.

#!/usr/bin/perl use strict; no strict 'refs'; use warnings; my $in16S = '/root/Desktop/pro.faa'; open I16S, '<', $in16S; my %r_genus16S; my ($genus16s) = <I16S>; while ( defined( ${'genus16S'} = readline(*I16S) ) ) { if ( $_ =~ />(\w+)\s/ ) { ${'genus16S'} = $1; } if ( exists $${'genus16S'}{ ${'genus16S'} } ) { print { 'I16S'; } $_; $${'genus16S'}{ ${'genus16S'} } = 'p'; next; } } my $no16S = 0; foreach $_ ( keys %${ 'r_genus16S'; } ) { if ( $${'genus16S'}{$_} eq 'n' ) { ++$no16S; print "$_\n"; next; } } close I16S;

Replies are listed 'Best First'.
Re^2: readline on closed filehandle error
by jwkrahn (Abbot) on Jan 24, 2012 at 07:23 UTC
    open I16S, '<', $in16S;

    You don't test that open succeeded so this code has the same problem as the OP's code.

    my %r_genus16S;

    You don't use this variable anywhere so why are you creating it?

    my ($genus16s) = <I16S>;

    That reads the entire file and assigns the first line to $genus16s.

    while ( defined( ${'genus16S'} = readline(*I16S) ) ) {

    Which means that this loop will never execute because I16S is already at EOF at this point.    And WTF is up with ${'genus16S'}?