What makes you think that your code, written in Perl, is faster than the Perl code for eval, written in C?
I would really recommend you move to a saner way of storing your configuration information, like a slash-delimited path to the target or a dot delimited path, like this:
blah.hat=splat cat=doh,ray
Then, assuming your data wouldn't contain commas, you could conveniently create your configuration information by using one of the Config modules. Or you could write your own parser for that (untested, ad-hoc code, see Data::Dumper for a better diving implementation):
... my $Config = { some => 'default values', }; while (<CONFIG>) { chomp; my ($key, $value) = split /=/,2; my @path = split /\./, $key; my $loc = $Config; my $last = pop @path; for (@path) { $loc->{$_} ||= {}; $loc = $loc->{$_}; }; if ($value =~ /,/) { # Store an array $loc->{$last} = [ split /,/, $value ]; } else { $loc->{$last} = $value; }; };
Also see Data::Diver for far more convenient diving into data structures.
In reply to Re: Creating data tree from input without eval
by Corion
in thread Creating data tree from input without eval
by cosmicperl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |