Rodrick Brown wrote:

> I have a few hundred records in a file like the following
> a:1
> a:2
> a:3
> b:1
> b:2
> b:3
> 
> I'm trying to build a hash of where the values on the left is the key and
> for each value on the right is an array containing the coresponding values
> I hope this makes sense
> 
> $a{$a} = [EMAIL PROTECTED]   where @values = {1,2,3}
> 
> I'm trying to do this on one pass if possible.
> 
> I'm have a bit of trouble contstructing this kind of data structure if
> anyone can help me out it would be appreciated thanks. .

my %a;
while ( <FILE> ) {
    chomp;
    my ( $key, $val ) = split /:/;
    push @{ $a{ $key } }, $val;
    }


John

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


Reply via email to