perlquestion
rnaeye
<p>Hi! </p>
<p> Script below inserts a line above SECOND </div> 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. </p>
<p>Thank you.</p>
<p>My script:</p>
<code>#!/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;
</code>
<p>Sample input file:</p>
<code> <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> </code>