Hashes!

Untested code:

while(<>){
   chomp;
   ($id,$name)=split(/\|/,$_);
   push( @($hash{$id}, $name) );
}

You can split the input file into chunks, or process one ID and then
let the variable go out of scope or whatever...

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


On 5/15/07, Andrej Kastrin <[EMAIL PROTECTED]> wrote:
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

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to