develooper Front page | perl.beginners | Postings from May 2007

transform one2many table

Thread Next
From:
Andrej Kastrin
Date:
May 15, 2007 14:55
Subject:
transform one2many table
Message ID:
464A2C43.2050400@siol.net
Dear all,
I want to transform one2many like table to one2one table. Original table 
looks as follows:

1|Michael
1|Alex
1|Bob
1|Pete
2|Bob
2|Andre
2|David
2|Alex
3|Pete

and the output should be similar to;
1|Michael Alex Bob Pete
2|Bob Andre David Alex
3|Pete

Table is large (4 GB), so I think the best idea is to process first n 
lines with unique id, print the result line and then process further. 
But I have no idea how to do that...

while(<>){
    chomp;
    ($id,$name)=split(/\|/,$_);
    $previous_id=$id;
    if($id eq $previous_id){
        push(@array,$name);
    }
### ???
}


Thanks in advance for any suggestion.

Best, Andrej

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About