Next Program Repair Shop 107

Many Very Long Strings

        print qq{
        <HTML>
        ...
        };
     print fill_template("order_thank_you.tmpl", 
                         NAME => "Ms. Betty White", CITY => "Hartford",
                         STATE => 'CT',  AMOUNT => 143.12,
                         PURCHASE => [ "Long Last Soft Shine Lipstick", 
                                       ... ]);
     sub fill_template {
       my $template = shift;
       my %data = @_;
       local (*TMPL, $/);
       open TMPL, "< $template" 
         or die "Couldn't open template file $template: $!; aborting";
       my $text = <TMPL>;
       no strict 'refs';
       # %%var%% is replaced with $data{var}
       $text =~ s/%%(\w+)%%/$data{$1}/g;  
       return $text;
     }


Next Copyright © 2002 M. J. Dominus