in reply to modify file in place in script? Regex for changing includes from SSI to PHP
Using Perl to create PHP. I love it! :)
It's not that you're "not doing that part right".
It's simply that you're "not doing that part".
You never write out your changes.
while ( my $html_file = $rule->match ) { # Change file in-place. local @ARGV = $html_file; local $^I = '.bak'; # Or '' to avoid making backups. while (<>) { ... # Keep (possibly edited) line print; } }
If you want something less magical,
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>) { ... # Keep (possibly edited) line print $fh_in $_; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: modify file in place in script? Regex for changing includes from SSI to PHP
by hmbscully (Scribe) on Oct 26, 2007 at 19:23 UTC | |
by ikegami (Patriarch) on Oct 27, 2007 at 16:07 UTC | |
by hmbscully (Scribe) on Oct 26, 2007 at 20:03 UTC |