Thanks for the suggestion. Unfortunately this approach won't work for the particular situation I'm dealing with, in which the string "templates", as it were, have to be defined before the interpolation can take place (which is why I can't just use qq{} in the first place).
Basically what I was experimenting with was having a set library of phrases whose contents would be interpolated in the appropriate context at a later time. Roughly: %messages = (
file_open_failed => 'unable to open $_[0]: $!',
some_other_error => 'had a problem doing $_[0]',
);
... stuff happens ...
open (INPUT, $filename) or die interpolate('file_open_failed', $file
+name);
(This behavior is actually encapsulated in an object, etc.; again, I've just stripped down for simplicity's sake.) Anyway, I got this all working fine initially using closures, and just started trying the eval-string approach as an alternative (TMTOWTDI...)
In any case, I appreciate the reminder about do's existence, since it's not something I use with any regularity! | [reply] [d/l] |