while( <FILE> ) { ( $key, $values ) = split; if( exists $hash{$key} ) { $hash{$key} .= ",$values"; } else { $hash{$key} = $values; } } -K "Do not meddle in the affairs of dragons, because you are crunchy and taste good with ketchup." > From: Pete Prodoehl <pete.prodoehl@cygnusinteractive.com> > Date: Thu, 12 Oct 2000 16:59:00 -0500 > To: "'macperl@macperl.org'" <macperl@macperl.org> > Subject: [MacPerl] Merging elements > > > I'm a bit stuck, and would appreciate any help. I've tried doing this with a > hash containing arrays, two separate arrays, and some other methods that > were even more ineffective. My head is starting to hurt... There's probably > some simple way to do this, I just can't figure it out... > > I'm reading in a file with data like this: > > aaa 438287,3231 > bbb 539634,4342 > ccc 558180,43555 > aaa 10878,8678666 > bbb 9274,6546 > ccc 23386,393 > > where 'aaa' is a key appearing twice, and the two separate pieces of data > (438287,3231 and 10878,8678666) need to be combined into one single piece of > data, represented by aaa, so I'm trying to get the outcome to be: > > aaa 438287,3231,10878,8678666 > bbb 539634,4342,9274,6546 > ccc 558180,43555,23386,393 > > any help or pointers would be appreciated... > > > Pete > > > # ===== Want to unsubscribe from this list? > # ===== Send mail with body "unsubscribe" to macperl-request@macperl.org > # ===== Want to unsubscribe from this list? # ===== Send mail with body "unsubscribe" to macperl-request@macperl.org