in reply to transform array into a data structure
Quick and dirty (not recommended):
# this breaks if @pathparts has a double quote in it! my $element = '$hash' . join '', map { qq|{"$_"}| } @pathparts; eval "$element = undef";
Slightly more respectable:
my $step = \%hash; while ( my $part = shift $pathparts ) { $step->{$part} ||= {}; $step = $step->{$part}; }
We might be able to help you better if you tell us what you're really trying to do (see XY Problem).
|
|---|