cbharath has asked for the wisdom of the Perl Monks concerning the following question:

Hi All, I have a small problem in reading from a file. I have a template file in which one of the line looks like this. Sam is riding a __VEHICLE__ ... I will be replacing __VEHICLE__ with a string value which i normally +get it from databse. Problem is, i will be using this variable '__VEH +ICLE__' at many places in my file. I need the value to be printed in +caps in some places and small letters in some places. I tried to print the value by placing \U....\E character in file itsel +f. But while printing, these escape characters are not recognized. Line in file :Sam is riding a \U__VEHICLE__\E ... replacing __VEHICLE__ with 'car' during reading Output Looks like this. Sam is riding a \Ucar\E ... Is there any way to recognize these characters from file and get the r +esult as expected.

Replies are listed 'Best First'.
Re: Reading escape characters from file
by wfsp (Abbot) on Oct 04, 2008 at 13:06 UTC
    Perhaps consider approaching the question from another angle and simply have two template vars.

    This uses HTML::Template to demonstrate a possible way to do it.

    #!/usr/local/bin/perl use strict; use warnings; use HTML::Template; my $tmpl = do{local $/;<DATA>}; my $t = HTML::Template->new(scalarref => \$tmpl); $t->param( vehicle_uc => q{BUS}, vehicle_lc => q{bus}, ); print $t->output; __DATA__ sam is riding an uppercase <TMPL_VAR vehicle_uc> sam is riding an lowercase <TMPL_VAR vehicle_lc>
    sam is riding an uppercase BUS sam is riding an lowercase bus
Re: Reading escape characters from file
by Anonymous Monk on Oct 04, 2008 at 13:02 UTC
    What template module are you using?
Re: Reading escape characters from file
by aufflick (Deacon) on Oct 05, 2008 at 11:45 UTC

    I second the suggestion to use a templating module - take a look at Template Toolkit, it should fit the bill.

    As for your question of two different formats, whatever your overall solution, why not just set up two variables for replacement. Call one vehicle and the other VEHICLE, or maybe VEHICLE and VEHICE_UC. In the perl code, make two replacements - one with the regular and other with the uc()'d version.