Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Removing redundancy

by samurai (Monk)
on Apr 26, 2003 at 02:49 UTC ( [id://253305]=note: print w/replies, xml ) Need Help??


in reply to Removing redundancy

I believe this will work (untested):

my @order = (); my %hash = (); while (<DATA>) { # split line on tab my @data = split /\t/; # for keeping the order push @order, $data[0] unless $hash{$data[0]}; # make an array ref if there isnt' one $hash{$data[0]} = [] unless $hash{$data[0]}; # store it away for later push @{$hash{$data[0]}}, $data[1]; } # keeping the order here for my $col1 (@order) { # get that stored array my $aref = $hash{$col1}; # print tab-delimited, grouped on col1 and in order print join("\t", $col1, @$aref), "\n"'; }

From what I gather what you asked, this is what you're looking for. If I didn't get it right you need to be more specific ^_^

--
perl: code of the samurai

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://253305]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-25 08:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found