in reply to building files from parsed html content
Something like this should work for the content replacement. If you actually need the script to determine the files as well, I'd recommend opendir and readdir, or File::Find.
Perl Codemy_file.html#! /usr/bin/perl use strict ; use warnings ; $|++ ; use Template ; my $tt = new Template ; foreach ( <DATA> ) { chomp ; open IN, $_ ; my @lines = <IN> ; close IN ; my $indata = join '', @lines ; my $outdata = '' ; $tt->process( 'template.tt2', { title => $_, content => $indata }, \$outdata ) or die $tt->error ; open OUT, ">$_" ; print OUT $outdata ; close OUT ; } exit ; __DATA__ my_file.html
template.tt2<center><h1>My File</h1></center> <hr /> <p>This is my file.</p>
<table align="center" width="75%"> <tr> <th>[% title %]</th> </tr> <tr> <td>[% content %]</td> </tr> </table>
|
|---|