John W. Krahn wrote:
Brian wrote:
Hello
Hello,
Having played around for a while, I am able to get a reasonable result
using Example 1, the unreasonable part being that l> gets added to the
end of the file, I can only presume here that it is duplicating the
last 2 characters of the last line in the file, that being </html>.
Q1. Am I presuming correctly, and how can I stop it happening?
I would like to be able to edit Example 2 that comes from John, so
that it comes out something like Example 3. The script fails as it
doesn't seem to like the addition of $New_folder/ in the first line.
Please point out the error of my ways.
I would like to be able to get both methods working so I can get to
better understand how to use either method.
#### Example 1
open (IN, "+<$New_Folder/dummy.html");
@file = <IN>;
seek IN,0,0;
foreach $file (@file){
$file =~ s/something/something-else/g;
print IN $file;
}
close IN;
##### Example 2
( $^I, @ARGV ) = ( '.bak', 'dummy.html' );
while ( <> ) {
if ( ? $search ? ) {
s/(?<= )$search(?= )/$replace/;
s!$date1!$date3!
and s!$date2!$1$today!;
}
print;
}
#### Example 3
( $^I, @ARGV ) = ( '.bak', '$New_Folder/dummy.html' );
You need to use double quotes so that $New_Folder is interpolated:
( $^I, @ARGV ) = ( '.bak', "$New_Folder/dummy.html" );
while ( <> ) {
s!something!something-else!
s!another-thing!another-thing-changed!
You need something besides whitespace to separate the two substitution
operators like "s///; s///" or "s/// && s///", etc.
}
You have a closing } without an opening {.
print;
}
John
Got it :-)
Thanks John
regards
Brian
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/