jonnyfolk has asked for the wisdom of the Perl Monks concerning the following question:
I am extracting data and putting it in a hash.
open FH, "$data" or die "Can't open $data: $!"; flock (FH, 1) or die "Can't lock $data for reading: $!"; foreach my $line (<FH>) { (undef,undef,undef,$email,$phone,$partners,$memberno) = split "\t", $l +ine; my @partnerssplit = split / /, $partners; $partners{$memberno} = \@partnerssplit; } close FH; print Dumper( \%partners);
$VAR1 = { 'fr065603' => [ 'fr065600' ], 'fr065601' => [ 'fr065600', 'fr065602' ], 'fr065604' => [ 'fr065600' ], 'fr065600' => [ 'fr065601', 'fr065602' ], 'fr065602' => [ 'fr065604', 'fr065603' ] };
Depending on the $level one requests, I would like to look up the values of the codes contained in the array value and extend the hash, extracting the final information as required.
The following snippet achieves the required result but doesnot extend the hash and it can be seen that extending the level would be quite complex
I'd be grateful if someone could point me in the right direction...} elsif ($level == 2) { foreach my $item (@{$partners{$base}}) { if (exists $partners{$item}) { push @allmembers1, $item, @{$partners{$item}}; foreach $item1(@allmembers1) { if (exists $partners{$item1}) { push @allmembers, $item1, @{$partners{$item1}}; } } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: creating a hash of arrays/hashes
by simonm (Vicar) on Mar 30, 2004 at 18:56 UTC | |
|
Re: creating a hash of arrays/hashes
by Happy-the-monk (Canon) on Mar 30, 2004 at 17:31 UTC | |
by jonnyfolk (Vicar) on Mar 30, 2004 at 17:59 UTC |