[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] interpolating




One way would be with the regexp:

   s/<!--(.*?)-->/$1/eeg;

But I usually want to put all my variables into a hash like %vars, then do
something like 

   s/<!--\$(.*?)-->/$vars{$1}/g;

Much less risky if you don't control the templates.


Nicholas.G.Thornton@directory.reed.edu (Nicholas G. Thornton) wrote:
>I'm working on a project that uses html templates replacing comments with the 
>appropreate variable.
>
>#####template#####
><html><body>hello <!--$name--></body></html>
>###############
>#####code#####
>#1perl
>$file = $ARGV[0];
>$name = 'bill';
>
>print "content-type: text/html\n\n";
>open FILE, "<$file" or die "cannot open '$file'";
>     while (<FILE>) {
>          s/<!--(.*?)-->/\1/;
>          print "$_";
>     }
>close FILE;
>__END__
>###############
>#####desired output#####
>content-type: text/html
>
><html><body>hello bill</body></html>
>###############
>
>or something along those lines will capture all instances of the
>variables that need replacing. But how would I interpolate $_ before
>sending it back? I mean something aside from a long list of
>s/\$name/$name/; etc

  -------------------                            -------------------
  Ken Williams                             Last Bastion of Euclidity
  ken@forum.swarthmore.edu                            The Math Forum



# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org