I have tried to put the script within a foreach loop, but it did not work.
So, I'm guessing that you didn't try it this way:
#!/usr/bin/perl
use strict;
use warnings;
for my $f ( @ARGV ) {
local $/;
open( I, '<', $f );
open( O, '>', "$f.bak" );
my $count = 0;
my $line = <I>;
$line =~ s{ (<\/div>) }
{ if (++$count == 2){
"\t<?php include(\$_SERVER['DOCUMENT_ROOT'].\"\/incl
+udes\/footer.php\"); ?>\n\n".$1;
} else {
$1;
}
}gex;
print O $line;
}
That works for me. (BTW, I'm compulsive about making the indentation look right -- seems silly, but it's really helpful to keep code less illegible.)
If you have so many files that you can't fit them all as args on a command line, there's the unix "xargs" tool:
ls | xargs your_prog ## or use "find ... | xargs your_prog"
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|