in reply to Removing redundancy
With that said and given your example data - I would:
#!/usr/bin/perl -w use strict; my %seen; my @data; open (INPUT,"file") or die "Error accessing file : $!"; while (<INPUT>) { chomp; my ($col1, $col2) = split /\t/; if (exists $seen{$col1}) { $data[$seen{$col1} - 1] .= " $col2"; } else { $seen{$col1} = push @data , "$col1\t$col2"; } } print "$_\n" foreach(@data);
Cheers - L~R
Update: Completely re-wrote code to be unique as my original solution closely mirrored others
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
| A reply falls below the community's threshold of quality. You may see it by logging in. |