in reply to Re^2: Different way to use while loop
in thread Different way to use while loop
not in scalar context which is enforced by the boolean context of the while condition.
see s///g in perlop, perlre , perlretut
In scalar context, successive invocations against a string will have //g jump from match to match, keeping track of position in the string as it goes along. You can get or set the position with the pos() function.
I was wrong the scalar thing is only valid for m//g , s///g just returns the number of all substitutions
DB<112> $_ = "a a a" => "a a a" DB<113> scalar s/a/x/g => 3
See this example in perlop for a similar use case
1 while s/(\d)(\d\d\d)(?!\d)/$1,$2/g;
But without knowing Foo and Bar we can only speculate.
|
|---|