[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Merging elements




This is barely tested and I'm running out the door ;-)

-dave

#!perl

use strict;

my %dataStore;

open (DATA, "<$ARGV[0]") or die ($!);

while (my $line = <DATA>)
{
	$line =~ /(\S*)\s+(\S*)\s?/;
	$dataStore{$1} .= "," . $2;
}

close (DATA);

foreach my $key (sort(keys %dataStore)) {
		        print $key, '=', $dataStore{$key}, "\n";
}




On Thu, 12 Oct 2000, Pete Prodoehl wrote:

> 
> 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