
BillKSmith
Veteran
Jan 21, 2014, 5:21 AM
Post #2 of 2
(2123 views)
|
Re: [meir] using loop variable in regex subsitution
[In reply to]
|
Can't Post
|
|
It does work! After the first substitution, there is no 'work' left to replace. Perhaps this is what you mean
use strict; my $find = "work"; my $replace; for ( my $replace = 0; $replace < 3; $replace++ ) { my $string = "why doesnt this work?"; print "string before regex = $string\n"; $string =~ s/$find/$replace/; print "string after regex = $string\n"; } Output:
string before regex = why doesnt this work? string after regex = why doesnt this 0? string before regex = why doesnt this work? string after regex = why doesnt this 1? string before regex = why doesnt this work? string after regex = why doesnt this 2? Good Luck, Bill
(This post was edited by BillKSmith on Jan 21, 2014, 5:43 AM)
|