in reply to Hash key manipulation question
use strict; use Data::Dumper; my @a = (1, 2 ,3 , "a"); my %h; a2h (\@a, \%h); print Dumper (\%h); print $h{1}{2}{3}{a}; sub a2h { my $array = shift; my $hash = shift; my $index = 0; while ( $index < $#$array ) { $hash = $hash->{$array->[$index]} = {}; $index++; } $hash->{$array->[$index]} = 1; return $hash; } #Output: # #$VAR1 = { # '1' => { # '2' => { # '3' => { # 'a' => 1 # } # } # } # }; #1
|
|---|