in reply to importing all the values stored in an HoH into an array
$hash =
{
total_counts => tot_counts,
words => {
nw => 1,
}
};
@finalarray = get_array($hash);
print "@finalarray";
sub get_array {
my($hash) = @_;
my $array = [];
if(ref $hash eq 'HASH') {
foreach (keys %$hash) {
if(ref $hash->{$_} eq 'HASH') {
push @{$array} , $_;
push @{$array} , get_array($hash->{$_});
}
else {
push @{$array} , $_;
push @{$array} , $hash->{$_};
}
}
}
return @$array;
}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: importing all the values stored in an HoH into an array
by chinamox (Scribe) on Oct 31, 2006 at 13:45 UTC |