ehdonhon has asked for the wisdom of the Perl Monks concerning the following question:
Hello,
I'm working on a small API for a project that I'm involved in at the moment. One of the things I want to be able to do is allow somebody to send me some template text along with placeholders for special information that my object knows about, and then return the text with the required information substituted in. Very similar to the way apache allows you to specify custom log formats.
It seems to me that using placeholders the way that printf does ( % then some identifier, perhaps with some formatting options) seems to be a standard way of doing this.
My main question: is there any module out there that specializes in parsing these kinds of template strings, or do I pretty much have to start from the ground up?
If I do have to start from the ground up, then I'm thinking that initially, I'm going to try something simple like this:
my $template_text =~ s/\%g/$g_var/g;
There are a ton of problems with this:
I really appreciate any assistance with this, especially if somebody can tell me that this has already been written! :)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Accepting a template string and replacing placeholders the way printf does.
by grep (Monsignor) on Jan 13, 2002 at 06:43 UTC | |
|
Re: Accepting a template string and replacing placeholders the way printf does.
by hossman (Prior) on Jan 13, 2002 at 07:24 UTC | |
by hossman (Prior) on Jan 13, 2002 at 13:49 UTC |