Well, the words "huge file" make me wonder if this is the right way to go, but if you want one entry per key, that's spelled "hash" in Perl. Here's a sample (untested) that should take you in the right direction:

my %hash; # crappy name but easy to remember while (<FILE>) # assuming FILE is open to the right place { my ($key, $value) = split /\t/; # only one tab per line push @{$hash{$key}}, $value; # magic of autovivification } # done, print everything foreach my $key (keys %hash) { print $key, " => ", join(' ', values @{$hash{$key}}, "\n"; }
The idea is to maintain a hash of the keys (your first column) and associate each with an array of values (your second column). The main problem this may face is that hashes take a lot of memory, so depending on your definition of "huge file", this may not work.

For more information, you may want to start with the Perl data structures cookbook.

Update
BrowserUK is correct below, hashes don't preserve input order. For that, the easiest modification is to use Tie::IxHash if you can take the time and memory hit.


In reply to Re: Removing redundancy by VSarkiss
in thread Removing redundancy by dr_jgbn

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.