PyrexKidd has asked for the wisdom of the Perl Monks concerning the following question:

The code below is designed to read a file into a hash, and then parse through a nother file. if the entry is found, the entry should be put in $BEEPON, if the entry is not found it should be put it $BEEPOFF.

the problem I am having is this error:

readline() on closed filehandle $LISTDEL at ./delete_list_ver3.pl line + 12 (#1) (W closed) The filehandle you're reading from got itself closed so +metime before now. Check your control flow.

Any thoughts? as far as I can tell the file is open... What is going on?

Thanks in advance.

#!/usr/bin/perl use strict; use warnings; use diagnostics; if (@ARGV = 2){ my %delList; open my $BEEPON, '>>', "./beepon.file"; open my $BEEPOFF, '>>', "./beepoff.file"; open my $LISTDEL, '<', $ARGV[0]; foreach (<$LISTDEL>){ chomp($_); $delList{$_} = 1; } open (my $ORGLIST, '<', $ARGV[1]); foreach my $entry (<$ORGLIST>){ chomp($entry); print { exists $delList{$entry} ? $BEEPON : $BEEPOFF } $entry +. "\n"; } close $LISTDEL; close $BEEPON; close $BEEPOFF; }

Replies are listed 'Best First'.
Re: Remove from List
by toolic (Bishop) on Aug 23, 2010 at 21:36 UTC

      Oh wow. Thank you guys. That was WAY too easy.

      Thanks for the assist. Should have seen that.

      now I'm kicking myself for the n00b m0ve.

        No problem: I come from Pascal, and I make that mistake about once a week. And I've been using perl for more than 6 years now...

        The real error is not to check the result of open and, in general, of all I/O operations, but that I make once a week, too :).

        Rule One: "Do not act incautiously when confronting a little bald wrinkly smiling man."

Re: Remove from List
by psini (Deacon) on Aug 23, 2010 at 21:32 UTC
    Any thoughts? as far as I can tell the file is open... What is going on?

    Check whether it is really so:

    open (my $LISTDEL, '<', $ARGV[0]) || die $!;

    (The same applies to the other open's, obviously)

    Update:

    It fails because

    if (@ARGV = 2){

    sets @ARGV to (2). Use ==

    Rule One: "Do not act incautiously when confronting a little bald wrinkly smiling man."

Re: Remove from List
by TomDLux (Vicar) on Aug 24, 2010 at 05:55 UTC

    I got tired of checking open() and other command return values ... now I use fatal qw( open close );

    As Occam said: Entia non sunt multiplicanda praeter necessitatem.