in reply to Array to nested hash
Recursive solution
Don't know if that's any more a perl way to do it.. but still a different way.use strict; use warnings; use Data::Dumper; my %uberhash; my @test = qw[1 2 3 4 5]; getFunky(\@test,\%uberhash); print Dumper(%uberhash); sub getFunky { my ($arr,$hash) = @_; if($#$arr != -1) { my $current = shift @{$arr}; if($#$arr == -1 ) {getFunky($arr,\$$hash{$current});} else {getFunky($arr,\%{$$hash{$current}});} } else { $hash => undef; return; } }
|
|---|