In simple terms the single > means to open a file from output starting it from the beginning, while the double >> means to open a file for output but to append what you are about to write at the end of anything that already exists. This write-append method will also open a non existent file and start writing from the beginning

In your case i would think that the write-append mode is dangerous. The files could fill up with repeated identical sequences because the id existed in more than one input file or you just ran the program a second time, for in write-append mode each run will just append the new data at the end of the existing file.

There are ways to tell if you have already encountered that id and wrote it to a file already. i might do it like this

foreach $id (keys %id2seq){ if (-f $id) { print $id." already exists. about to overwrite i +t\n";} open my $out_fh, '>', $id or die $!; ##Amendment here print $out_fh ($id."\n",$id2seq{$id}, "\n"); close $out_fh; ## moved into the foreach loop }
Note the change to write-from-beginning, and the test to see if the file already exists. This way there would only be the last sequence found in any give file.


In reply to Re^4: I'm trying to print the contents of a hash to newly created files by huck
in thread I'm trying to print the contents of a hash to newly created files by Peter Keystrokes

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.