A slow-to-arrive answer: This here will print out the first field in the first occurrence of each of your six keys.
#!/usr/bin/perl open (SIX,"</home/adamsj/sixtext"); @lines = <SIX>; close(SIX); foreach (@lines) { chop; @a_line = split(/,/); $key = shift @a_line; push(@{$all_of_it{$key}},[@a_line]); } foreach (keys %all_of_it) { print "$all_of_it{$_}[0][0]\n";}
This should give you an idea how to do it--you could look in the Perl docs for more on this. I think the best treatment of references is in Advanced Perl Programming by Sriram Srinivasan (not that I have a copy--I used to borrow someone else's), but there are a lot of other good Perl books out there. This _is_ moderately advanced Perl--if you have trouble with this example, try working up to it with this:
foreach (@lines) { chop; ($key, $line) = split(/,/, $_, 2); push(@{$all_of_it{$key}},$line); } foreach (keys %all_of_it) { print "$key,$all_of_it{$_}[0]\n";}
What this does is split the line into the key and the remainder of the line, then puts the line into an array keyed by your, well, your key. It'll print out the entire line from the first occurence of each $key. Once you see how this one works, go for the more complex example. Good luck--I found this tricky at first, too.

In reply to Re: Creating the right type of array... by adamsj
in thread Creating the right type of array... 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.