in reply to Different way to use while loop
1 while s/^FOO/BAR/g;
repeats the substitution till it fails¹ ...
...which doesn't make much sense because of the ^ anchoring at the start, i.e. it can't substitute more than once.
This should lead to the same results
while (<FH>) { s/^FOO/BAR/; print "$_"; }
The rest (iterating over lines from filehandle with $_) should be obvious, right?
If not have a look at perlintro
while (s/^FOO/BAR/g) { 1 ; # no op }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Different way to use while loop
by Anonymous Monk on Jan 09, 2015 at 03:48 UTC | |
by LanX (Saint) on Jan 09, 2015 at 03:52 UTC | |
by dsheroh (Monsignor) on Jan 09, 2015 at 12:40 UTC |