I’m reading strings from a file. Those strings contain escape sequences which I would like to have evaluated before processing them further. So I do:
$t = eval("\"$t\"");
which works fine. But I’m having doubt about the performance. If eval is forking a perl process each time, it will be a performance killer. Another way I considered to do the job were regex, where I have found related questions in SO.
My question: is there a better, more efficient way to do it?
EDIT: before calling eval in my example $t is containing \064\065\x20a\n. It is evaluated to 45 a<LF>.
It’s not quite clear what the strings in the file look like and what you do to them before passing off to
eval. There’s something missing in the explanation.If you simply want to undo C-style escaping (as also used in Perl), use
Encode::Escape:If you have placeholders in the file which look like Perl variables that you want to fill with values, then you are abusing
evalas a poor man’s templating engine. Use a real one that does not have the dangerous side effect of running arbitrary code.