twaddlac has asked for the wisdom of the Perl Monks concerning the following question:
So it seems like every time write a script that reads and writes to a file I get this error:
print() on closed filehandle DATA_1 at compare_names.pl line 33, <SECO +ND> line 773874
The error above is specific for the code below, but none the less it's telling me the same thing. If you have any ideas on how to stop the compiler from yelling at me all the time I would greatly appreciate it! Thank you very much!
#! usr/bin/perl -w use strict; use warnings; print "What is the filepath of Jay's file?\n"; my $first_file = <STDIN>; print "And the mine?\n"; my $second_file = <STDIN>; open FIRST, $first_file; open SECOND, $second_file; open DATA_1, "</home/Alan/Desktop/sequence_data/sequence_comparison/Ja +ys_unique.txt"; #open DATA_2, "/home/Alan/Desktop/sequence_data/sequence_comparison/my +_unique_results.txt"; while(<FIRST>){ my $name_1 = $_; my $match = 0; while(<SECOND>){ my $name_2 = $_; if($name_1 eq $name_2){ $match = 1; last; } } if($match != 1){ print DATA_1 $name_1,"\n"; } } close FIRST; close SECOND; close DATA_1;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: print() on Closed File Handle Error!
by Fletch (Bishop) on Aug 13, 2010 at 18:36 UTC | |
|
Re: print() on Closed File Handle Error!
by kennethk (Abbot) on Aug 13, 2010 at 18:42 UTC | |
|
Re: print() on Closed File Handle Error!
by twaddlac (Novice) on Aug 13, 2010 at 18:59 UTC | |
by lostjimmy (Chaplain) on Aug 16, 2010 at 15:04 UTC | |
by dasgar (Priest) on Aug 13, 2010 at 19:07 UTC | |
by kennethk (Abbot) on Aug 13, 2010 at 19:12 UTC | |
by dasgar (Priest) on Aug 13, 2010 at 19:25 UTC | |
by Marshall (Canon) on Aug 15, 2010 at 01:19 UTC |