in reply to arrays from arrays
So you say you have multiple values for certain keys.
key => value,value,value
This directly translates to Perl:
my %hash = ( key => [ value, value, value ], ... );
We call this a HoA, a hash of arrays as every value is another (anonymous) array-reference.
The creation of such a data structure is very easy with Perl as it has magic autovivification:
use Data::Dumper qw/Dumper/; my %hash = (); while( <DATA> ){ chomp; my ($k,$v) = split /\s*:\s*/; push @{ $hash{ $k } } , $v } print Dumper( \%hash ); __DATA__ green : apple yellow: banana green : kiwi red : strawberry green : mango yellow: lemon
That's it. Perl is great. update: see perlref and perldata of course.
--http://fruiture.de
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: arrays from arrays
by Anonymous Monk on Mar 07, 2003 at 17:50 UTC |
In Section
Seekers of Perl Wisdom