Re: Help, infinite loop on a simple replacement??
- From: "Xicheng" <xicheng@xxxxxxxxx>
- Date: 31 Jan 2006 12:06:52 -0800
pierre_catello@xxxxxxxx wrote:
> Hello,
>
> When trying to replace every % by %25 in a file, my substitution
> command goes into an infinite loop.
>
> while ($input =~ s/%/%25/sg) {}
I guess you mixed up s///g with m//g. $input =~ s/%/%25/sg will always
return the number of substitutions made(s/// returns 0/1 if there is no
'g' modifier). So as long as you get any success match, the condition
in "while" clause will be true. so you get an infinite while loop..
to replace globally, just use the following line:
$input =~ s/%/%25/sg;
Xicheng
>
> I suspect that inserting a beginning % in the replacement string should
> be the problem (as successive application of the command will match
> it).
> What is the right way to do it?
.
- References:
- Help, infinite loop on a simple replacement??
- From: pierre_catello
- Help, infinite loop on a simple replacement??
- Prev by Date: Re: Mechanize and substitution on content, then save
- Next by Date: Can't locate object method "TIEHASH" via package "Apache::Session::MySQL"
- Previous by thread: Re: Help, infinite loop on a simple replacement??
- Next by thread: Can't locate object method "TIEHASH" via package "Apache::Session::MySQL"
- Index(es):
Relevant Pages
|
|