I'll try to give you a skeleton of that subroutine:
sub ExtractDatabaseFields { my $file= shift; my @databases= @_; my %result; foreach my $database (@databases) { my @fields= ... #extract data from database my $nextfield= .... #find next field $result{$database}{next}= $nextfield; $result{$database}{fields}= \@fields; } return \%result; } #------------------- # Accessing my $result= ExtractDatabaseFields($file,@databases); #print next available field of database 27: print $result->{"27"}{next}; #extract the fourth field from database 27: my $field3= $result->{"27"}{fields}[3]; #add another field to database 27: push @{$result->{"27"}{fields}}, "whatever"; #loop over the fields of database $x: foreach $field ( @{$result->{$x}{fields}} ) { .... }
The resulting data structure would be a HashOfHashOfArrays, not a HashofArrays, but this makes the access to the data much clearer. If this isn't what you wanted you might give a more elaborate example
In reply to Re^3: Hash of Arrays or Arrays of arrays? and how proceed?
by jethro
in thread Hash of Arrays or Arrays of arrays? and how proceed?
by paride
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |