in reply to Re: 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
rename($html_file, "$html_file.bak") or die;
Makes a copy of the file with the .bak extension
open(my $fh_in, '<', "$html_file.bak") or die;
Opens the copy of the file for reading
open(my $fh_out, '>', $html_file) or die;
Opens the original file for writing, wiping out the contents?
while (<$fh_in>) {
while there are file contents in the backup file, do something with them
# Keep (possibly edited) line print $fh_in $_; }
Print whatever the backup file is back into the backup file?
Ok, yeah, I still don't get this. I know I should, I've read enough examples, but I don't.
I read it as making a copy of the file I want to change, wiping out the contents of the original, modifying the copied file somehow and writing the modified text back into the copied file? Why am I not seeing this still?
Also, I don't get the while(<$fh_in>) { s/// } instead of using
because do I want to do the s/// on the entire file at once? Don't I want to go line by line?my @lines = <$fh_in>; for (@lines) { s/// }
As for the using Perl to write PHP, as ignorant as I may seem about Perl, I am continuously frustrated with moving into PHP. What I find is that the things that PHP does easier than Perl does not outweight the things that I could do easily in Perl that cannot do easily in PHP.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: modify file in place in script? Regex for changing includes from SSI to PHP
by ikegami (Patriarch) on Oct 27, 2007 at 16:07 UTC | |
|
Re^3: modify file in place in script? Regex for changing includes from SSI to PHP
by hmbscully (Scribe) on Oct 26, 2007 at 20:03 UTC |