MorayJ has asked for the wisdom of the Perl Monks concerning the following question:
Hi,
I'm trying to do a substitution in a file
I am trying to match:
<input type="checkbox" ng-model="data.mydebts.loan[0]"
I then want to switch it out so it says
<input type="checkbox" ng-model="data.mydebts.loan[0]" label="loan"
I am trying the following code:
while ($my_file =~ /(input type=\"checkbox\".*?(\w+)\[0\])/sg) { $my_file =~ s/$1/$1 label="$2"/s; };
But, although the match works when I print it out ($1 prints the line I want to match), it doesn't work when I use it in the substitution.
Even if I replace the substitution with a literal switch like
s /$1/TEST/s;
I think this is because the match($1) has a newline and some spaces in it
If that's the case, how do I tell it to use exactly what's in the match in the substitution (and why doesn't it do that anyway)?
Or have I probably made a mistake somewhere?
Thanks for your help
MorayJ
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Substituting with match containing newline and space characters
by choroba (Cardinal) on Mar 30, 2015 at 13:12 UTC | |
by MorayJ (Beadle) on Mar 30, 2015 at 13:43 UTC | |
|
Re: Substituting with match containing newline and space characters
by kroach (Pilgrim) on Mar 30, 2015 at 13:18 UTC | |
by MorayJ (Beadle) on Mar 30, 2015 at 13:46 UTC | |
by jeffa (Bishop) on Mar 30, 2015 at 18:11 UTC | |
by MorayJ (Beadle) on Mar 31, 2015 at 11:27 UTC |