hi monks,
I have a file with data like this:

id_1 info1
id_2 info2
id_3 info3

id_1 info1
id_2 info2
id_3 info3
and all I want to do is use a hash to put this into arrays eg: id_1 all the info with this id here...
so id is my key.
Here's the code:
while (<MYFILE>) { { next if /^\s*CLUSTAL/; #remove line starting with CLUSTAL + heading next if /:/; #skip the consensus lines which contain : +and * next if /\*/; next if /^ /; my($id, $seq) = split; #splits each line to +id and sequence $newid = substr ($id, 0, 9); #remove all but 9 characters from +id #so the id's are all the same length push @{$species{$newid}}, $seq; #each time adds +sequence to #a unique id and puts sequence in an + array (hash is %species) } } while (($key, $sequence)=each %species) { print DATA ">", $key, " ", join " ", @$sequence; #\t to sep +arate with tab print DATA "\n"; } close(MYFILE); close(DATA);
the problem is, I seem to get a blank record printed out at
the top of the page - I am adding the symbol > to the front of each id

what I get in my DATA file is

>
>id1 info
>id2 info

any idea why I get this blank record printed first?
thanks

In reply to hash printing - why a blank record ? by Anonymous Monk

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.