Carrie Lyn Brammer wrote at Fri, 19 Jul 2002 10:46:51 +0200:

> $contents = <FILE>;

I think,
the simplest change is to read the FILE at once as one string -
of course only if the files are too big.

$contents = join "", (<FILE>);

> # a loop that will go through each line of the document. Implement the user input 
>into  a regular
> expression # order to search and replace. If a replacement is made, it should ask 
>the user if they
> want to continue. # If they don't the program will close. If they do, it will 
>continue searching
> the rest of the file. 
> while ($contents =~ s/$text/$replacetext/gi){

If you want to replace text and not regular expressions,
it's better to quote the text via \Q:

$contents =~ s/\Q$text/$replacetext/gi

The difference can be seen, e.g.
if anybody wants to replace "$ 100".

>     print "Made a replacement per your request. Would you like to continue? Type yes 
>or no \n";
>     chomp($answer = <STDIN>);
>         unless ($answer = "yes"){
                          ^^
You definitly meant $answer eq "yes",
as the = is a simple assignment, returning the value assigned,
what will mean that even if you type no,
the answer is set to "yes".

>             die "Program will not continue per your request\n";
>         }
>     $contents = <FILE>;

If you read the file at once,
you won't need thap loop anymore.

>     $counter++;
> }
> }
> # print how many matches/replacements the program made print "The program is 
>complete. It replaced
> $counter matches\n";
> 
> # close the file
> close (FILE);


Best Wishes,
Janek


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to