in reply to Replace placeholders in text in an elegant manner

Use a template.
use Text::Template; my $template = Text::Template->new( type => "FILEHANDLE", source => *DATA, ); my $text = $template->fill_in( hash => { placeholder1 => "chicken", placeholder2 => "dog", }, ); print $text; __END__ This is text with { $placeholder1 }. It can be with { $placeholder2 } too. { $placeholder1 } can appear more than one time in the text.

Replies are listed 'Best First'.
Re^2: Replace placeholders in text in an elegant manner
by CountZero (Bishop) on Feb 28, 2010 at 08:42 UTC
    Aw come on! Don't spoil it for the OP.

    Reinventing a web-framework or a templating system must be one of the rites of passage of becoming a real Perl programmer.

    ;-)

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James