An idea that might or might not work, depending on how similar and consistent your "perl-strings" are:
my %dbhash = ( name => 'revdiablo', prize => 'pony', ); my $template = 'Hello $dbhash{name}, you won a $dbhash{prize}.'; #$template =~ s/\$dbhash{([^}]+)}/$dbhash{$1}/ge; # unnecessary $template =~ s/\$dbhash{([^}]+)}/$dbhash{$1}/g; print "$template\n";
Update: of course, you might notice that this too uses eval. It just does it in a more constrained manner. I don't know how the difference in performance will work out, but I think it's much less dangerous in any event.
Another Update: aye, I just realized the /e is unnecessary, as the replacement part of a s/// is already interpolated as a double-quoted string. It can simply be s/\$dbhash{([^}]+)}/$dbhash{$1}/g.
In reply to Re: More Efficient Than Eval
by revdiablo
in thread More Efficient Than Eval
by geekondemand
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |