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

Unworthy hack that I remain... I beseech mercy and humbly request the honored for direction to a script so I can modify for the following task:
==================
I can strip out either the header or footer server includes calls in the multitude of over 3000 html files.

Now....
I want to take the remaining hard coded html content of the files and port it into a table cell in a new template I've built and have the script save the new file with the original file name.

So, What I think I need to do is locate a script that finds the file name of each of the 3000 files, input the remaining html code, and build a file with the original name using my new template.

The new template will be a table so i figure I can have a place marker in that table cell, and input the remaining html code of each file into that cell.

Do you know of a script close to this plan i can modify?

Do you have any other suggestions how-to automate this process; namely:

grep/join/build a new file using the original name for the thousands of html files?

much obliged,
unworthy hack Stretch
  • Comment on building files from parsed html content

Replies are listed 'Best First'.
Re: building files from parsed html content
by DamnDirtyApe (Curate) on Aug 02, 2002 at 00:23 UTC

    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 Code
    #! /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
    my_file.html
    <center><h1>My File</h1></center> <hr /> <p>This is my file.</p>
    template.tt2
    <table align="center" width="75%"> <tr> <th>[% title %]</th> </tr> <tr> <td>[% content %]</td> </tr> </table>

    _______________
    D a m n D i r t y A p e
    Home Node | Email