lcschreier has asked for the wisdom of the Perl Monks concerning the following question:
I've tried to use the following expression:
if ($string =~ m/(p1)(p2)(p3)/) { rest of block
which captures p1 into $1 p2 into $2 and p3 into $3 as I expect it should.
the question is this: when I try to substitute:
($new1 = $1) =~ s/this/that/;
($new2 = $2) =~ s/this2/that2/;
($new3 = $3) =~ s/this3/that3/;  (and so on)
I get a runtime error (uninitialized value) even though, for the exact same $string and m// when I split the expression into:
$new1 = $1;
$new2 = $2;
$new3 = $3;
$new1 =~ s/this/that/;
$new2 =~ s/this2/that2/;
$new3 =~ s/this3/that3/;
I don't get a runtime error (undefined or other).
I didn't think I was modifying $1 ($2 or $3) so thought the initial substitution should work. I'm wondering what I missed in this case.
thanks in advance
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: modifying en passant
by almut (Canon) on Jan 09, 2010 at 22:47 UTC | |
by lcschreier (Novice) on Jan 10, 2010 at 22:41 UTC | |
|
Re: modifying en passant
by chromatic (Archbishop) on Jan 09, 2010 at 22:35 UTC | |
|
Re: modifying en passant
by ikegami (Patriarch) on Jan 10, 2010 at 08:48 UTC | |
by lcschreier (Novice) on Jan 10, 2010 at 23:03 UTC | |
|
Re: modifying en passant
by sflitman (Hermit) on Jan 09, 2010 at 22:39 UTC | |
by GrandFather (Saint) on Jan 09, 2010 at 22:47 UTC |