The following may be what you're seeking:

#!/usr/bin/perl use warnings; use strict; use 5.012; # 902200 my @lines = qw( >seq1 ASDFGHASDFGHJ ERTYUIOOIUYLK NBGFEWERTY >seq2 BGTNHYMJUKOPK MNBFSDFGHJ >seq3 USE_STRICT&USE_WARNINGS lastline ); my $line; my ($DNA, $seq); # descriptive var names my %all_hash = (); for my $line (@lines){ # insert after this line, see update 2 chomp $line; if ($line =~ /^>(seq\d)/ ) { # captures seq# withOUT the '>' $seq = "$1\n"; say "\n\$seq: $seq"; # useful for debug; otherwise, not } else { $DNA = "$line\n"; say "\$DNA: $DNA"; } no warnings; #otherwise, warns 'unitialized' for the first +$DNA $all_hash{ $seq } .= $DNA; # concat $DNAs, which now # have '\n's restored for readab +ility use warnings; } print "\n =============== \n"; print %all_hash;

Output (when fixed as per update 2):

$seq: seq1 $DNA: ASDFGHASDFGHJ $DNA: ERTYUIOOIUYLK $DNA: NBGFEWERTY $seq: seq2 $DNA: BGTNHYMJUKOPK $DNA: MNBFSDFGHJ $seq: seq3 $DNA: USE_STRICT&USE_WARNINGS $DNA: lastline =============== seq1 ASDFGHASDFGHJ ERTYUIOOIUYLK NBGFEWERTY seq3 USE_STRICT&USE_WARNINGS lastline seq2 BGTNHYMJUKOPK MNBFSDFGHJ

Update

Added comment re say at line 29

Update2 : Missed a serious mistake here: the concat at line 36 actually inserts the last $DNA from the previous $seq into each new $seq. Bad on me! A fix is to reset $DNA to an empty string by inserting $DNA = ''; as a new line 26.


In reply to Re: inputting into hash error by ww
in thread inputting into hash error by mabeuf

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.