in reply to Re^2: Dynamic population of a hash
in thread Dynamic population of a hash
It's not at all clear why you'd be putting that into a hash as you illustrate. It would be more interesting to make a multilevel hash that mimics the hierarchy of a list of paths:my @values = split m:/:, $path_string;
That might be a bit much to absorb so early in your Perl experience, but maybe not.my $hashed_path = {}; for my $path_string (@list_of_paths) { my $hpref = $hashed_path; for $dir (split m:/:, $path_string) { $hpref->{$dir} = {} unless exists $hpref->{$dir}; $hpref = $hpref->{$dir}; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Dynamic population of a hash
by Anonymous Monk on Nov 09, 2005 at 15:12 UTC | |
by Roy Johnson (Monsignor) on Nov 09, 2005 at 15:41 UTC |