in reply to Removing redundancy in X and Y directions

I'd probably use a hash of hashes for this (see perldsc). The top level keys would be your "text1" and "text2". Second level keys would be "text-a", "text-b", etc. The values would just be 1 or something. When you're done, loop over the keys of the top level, and in the loop, get the keys of the second level. It may help to know what's in perlreftut and perlref.

If you get stuck, post the code you have, and we can help further.

Replies are listed 'Best First'.
Re^2: Removing redundancy in X and Y directions
by Anonymous Monk on Sep 26, 2008 at 15:55 UTC
    The code that I was trying to modify was...
    my %hash;
    while(<DATA>){
    chomp;
    my @line = split /\t/;
    my $first = shift @line;
    push( @{$hash{$first}}, @line );
    }
    foreach( sort keys %hash ){
    print OUT "$_\t".join("\t", sort @{$hash{$_}})."\n";
    }
      my %hash; while(<DATA>){ chomp; my @line = split /\t/; my $first = shift @line; $hash{$first}{$_}++ for @line; } foreach( sort keys %hash ){ print STDOUT "$_\t".join("\t", sort keys %{$hash{$_}})."\n"; } __DATA__ text1 text-a text-a text-b text-a text1 text-c text2 text-a text-b text2 text-b text-d

      All I changed was the push line and the print line. Output:

      text1 text-a text-b text-c text2 text-a text-b text-d