amw1 has asked for the wisdom of the Perl Monks concerning the following question:
I have code that works but I'm not terribly happy with it and I know there is some foo I'm missing somewhere. Below is the code I have working:@foo = qw[1 2 3 4 5]; should transform into a hash that looks like this $bar->{1}{2}{3}{4}{5} = undef;
As I said, this works but I feel there is probabbly a much more perlish way to do it. I searched a bunch of different places and didn't find much other than the normal perldsc type stuff.use Data::Dumper; use strict; use warnings; my $hashref; my @foo = qw[1 2 3 4 5]; my $string = "\$hashref->"; foreach my $item (@foo) { $string .= "{$item}"; } $string .= "= undef"; eval($string); print Dumper($hashref);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Array to nested hash
by davido (Cardinal) on Nov 08, 2004 at 16:48 UTC | |
|
Re: Array to nested hash
by tinita (Parson) on Nov 08, 2004 at 16:52 UTC | |
|
Re: Array to nested hash
by Limbic~Region (Chancellor) on Nov 08, 2004 at 16:51 UTC | |
by tinita (Parson) on Nov 08, 2004 at 17:18 UTC | |
by Mutant (Priest) on Nov 08, 2004 at 16:53 UTC | |
by amw1 (Friar) on Nov 08, 2004 at 17:20 UTC | |
|
Re: Array to nested hash
by tmoertel (Chaplain) on Nov 09, 2004 at 02:04 UTC | |
|
Re: Array to nested hash
by habit_forming (Monk) on Nov 08, 2004 at 17:09 UTC | |
|
Re: Array to nested hash
by Grygonos (Chaplain) on Nov 08, 2004 at 17:50 UTC | |
|
Re: Array to nested hash
by NetWallah (Canon) on Nov 09, 2004 at 00:56 UTC | |
|
Re: Array to nested hash
by TedPride (Priest) on Nov 09, 2004 at 09:16 UTC |