FAQ

sb@missionstclare.com wrote:
I am changing entire files.

I maintain missionstclare.com. I can create the daily files from Perl
scripts (and I do). Example at
http://www.missionstclare.com/english/March/morning/01m.html

But, to create the stripped-down versions of the same files (example at
http://www.missionstclare.com/english/March/whole/morning/01m.html), I
have to remove a great amount of stuff from the original daily files.

Like Tim, I've been using while(<>); but, from this discussion, I
suspect that while(<>) is the problem.

I've never used Slurp.
Now I think I see what the problem is. You are doing something like this:

while ( my $text = <FH> ) {

$text =~ s/george/tim/;

}

Which substitutes 'tim' for 'george' each time the value in $text
changes, which is for each line in the file.

If you only want the first instance of 'george' changed in the whole
file then you could use the spacial ?? pattern match:

while ( my $text = <FH> ) {

$text =~ ?george? && $text =~ s/george/tim/;

}



John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction. -- Albert Einstein

Search Discussions

Discussion Posts

Previous

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 8 of 8 | next ›
Discussion Overview
groupbeginners @
categoriesperl
postedFeb 22, '12 at 2:37a
activeFeb 23, '12 at 1:07a
posts8
users5
websiteperl.org

People

Translate

site design / logo © 2022 Grokbase