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
In reply to modifying en passant by lcschreier
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |