Brutha has asked for the wisdom of the Perl Monks concerning the following question:
This works fine, as long I have a string stored in $replace. But I need capturing and then it fails, it inserts a '$1' instead of the value. If I just do a$value = s/$search/$replace/;
I get the desired result in '$1'.m/$search/; print $1;
Can anybody point me to the solution?
For example I want to find single digit numbers and give them a leading zero. These are embedded in a varying string. So it could be something like
my $search = qr/No\s+(\d)$/; my $replace = 'No 0$1'; $title =~ s/$search/$replace/;
And it came to pass that in time the Great God Om spake unto Brutha, the Chosen One: "Psst!"
(Terry Pratchett, Small Gods)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Variable substitute and capturing
by ikegami (Patriarch) on Jan 16, 2006 at 16:46 UTC | |
by Brutha (Friar) on Jan 16, 2006 at 20:42 UTC | |
|
Re: Variable substitute and capturing
by davidrw (Prior) on Jan 16, 2006 at 16:44 UTC | |
by ikegami (Patriarch) on Jan 16, 2006 at 16:48 UTC | |
by davidrw (Prior) on Jan 16, 2006 at 16:54 UTC | |
by ikegami (Patriarch) on Jan 16, 2006 at 17:08 UTC | |
|
Re: Variable substitute and capturing
by Errto (Vicar) on Jan 16, 2006 at 23:25 UTC |