http://qs321.pair.com?node_id=906190

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

Hi!

Script below inserts a line above SECOND

tag in the text file. This script works fine when I have single input file. I would like to process hundreds of files at once. I have tried to put the script within a foreach loop, but it did not work. I was wondering if anyone could help.

Thank you.

My script:

#!/usr/bin/perl use strict; use warnings; $^I = ".bak"; undef $/; my $count = 0; my $line = <>; $line =~ s { (<\/div>) } { if (++$count == 2){ "\t<?php include(\$_SERVER['DOCUMENT_ROOT' +].\"\/includes\/footer.php\"); ?>\n\n".$1; } else { $1; } }gex; print $line;

Sample input file:

<html lang="en"> <body> <!-- a lot of text here --> <div id="masthead" > <!-- a lot of text here --> </div> <!-- ############################################### --> <div id="wrapper" > <!--a lot of text here--> </div> </body> </html>