Three things:

  1. You assign your $1 into a hash but print from an array. As others have said, it's best to assign into an array, using push().
  2. You create a variable, %slotarray, whose scope terminates with the end of the if block. Therefore, the variable is undefined when you go to print. You need to declare the variable at a scope visible to all uses of the variable, in this case, globally. Others have corrected your error, but not explained it.
  3. You don't do actually anything with the saved data.

    Instead of saving $1 into an array, you might as well print it when you find it. But assuming you did plan to do something more sophisticated, such as sorting the elements, you don't need to print the array using a loop ... that's such a C thing to do. Perl is efficient when you deal with sets of data all-at-once, letting Perl do the iterating.

    You might use join():

    print OUTFILE join( "\n", @slotarray ), "\n";

    Alternately, you could locally redefine the $LIST_SEPARATOR, $" :

    { local $" = "\n"; print OUTFILE "@slotarray\n"; }

--
TTTATCGGTCGTTATATAGATGTTTGCA


In reply to Re: $1 into an array by TomDLux
in thread $1 into an array by jamen_98

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.