Consider the following code.
print chg("word", qr/(\d)/); # print "nope" "2" =~ /(2)/; print chg("word", qr/(\d)/); # print "yes" sub chg { $_[0] =~ $_[1]; return $1 ? "yes\n" : "nope\n"; }
"2" =~ /(2)/ sets $1 to 2, which inadvertently affects chg() since chg() checks $1 for valid condition but $1 was set from outside.
If I'm using someone else's code where it might be using $1 for various things that I might not be aware of, is there anything I can do to avoid such a trap? It's kind of hard to track down such things in a large script. Thanks.
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |