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
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to