in reply to Re^2: modify file in place in script? Regex for changing includes from SSI to PHP
in thread modify file in place in script? Regex for changing includes from SSI to PHP

Ok, I studied the code some more and tested and tried and realized the < and > were reversed. This is what I've got now and it seems to work and I think I get it:

while ( my $html_file = $rule->match ) { rename($html_file, "$html_file.bak") or die; open(my $fh_in, '<', "$html_file.bak") or die; open(my $fh_out, '>', $html_file) or die; while (<$fh_in>) { my @lines = <$fh_in>; for (@lines) { #replace <!--#include virtual="[document path]"--> #with <?php include($_SERVER['DOCUMENT_ROOT'].'[document p +ath]'); ?> if (s/<!--#include virtual="(.*)"-->/<?php include(\$\ +_SERVER['DOCUMENT_ROOT'].'$1');?>/){ my $result = $1; #print the file changed and the document path for the + included file print OUTFILE "$html_file: $result\n"; } print $fh_out $_; } close($fh_in); close($fh_out); }

I learn more and more about less and less until eventually I know everything about nothing.
  • Comment on Re^3: modify file in place in script? Regex for changing includes from SSI to PHP
  • Download Code