Hey Monks!

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;

In reply to print() on Closed File Handle Error! by twaddlac

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.