Oct 4, 2011, 4:43 AM
Post #1 of 3
I have just spent ages trying to get a variable to work as the substitution part of a regexp. It continued to contain the first assignation to the variable, and not subsequent changes.
Flummoxed by variable in regexp
Couldn't understand why I couldn't find a comprehensible answer - nearest was finding /ee and eval blocks which, to be honest, I was not really understanding.
Anyway, had got in the habit of just trying to change something in the line to see if it would work.
So my substitution looked like this:
$line =~ s/DATE/$newdate/;
This resulted in $newline only ever concerning its first assignation - in effect, it became static.
I had the line:
following on from it, and this was updated with the new date. Frustration, bitterness and incomprehension followed.
I then thought I would post the problem and decided to tidy it up so it was doing exactly what I wanted.
$line = s/\(\d.*?\)/\($newdate\)/;
And suddenly $newdate in the substitution is updating and working fine.
Is there anyone who could explain this to me?