in reply to More Efficient Than Eval
If all you are doing is putting variables into the strings -- assuming that you are creating the strings also -- just put a marker in the string and replace it with a regex substitution. Instead of writing "Hello $dbhash{name}, you have...", just write "Hello NAME, you have..." and do
foreach $string_to_fill_in (@strings) { $string_to_fill_in =~ s/\bNAME\b/$dbhash{name}/g; # repeat for as many parameters as you have }
If you need more complex behavior, consider storing a template string from one of the major templating modules (e.g. HTML::Template) and use the template module to fill in your data.
-xdg
Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.
|
|---|