in reply to Re^3: Two hash keys created when '.' is in the string
in thread Two hash keys created when '.' is in the string
You shouldn't ever need to use "$2". It's just the same thing as $2.Not always. Given: sub foo { $^O=~/((.*))/; print for @_ } (a sub that happens to use a regex before accessing its args), foo("$2") if "foobar"=~/(...)(...)/ does something very different from foo($2) if "foobar"=~/(...)(...)/ You should always put magic variables in quotes when passing to a function to prevent this kind of action-at-a-distance.
Another case where you need to double-quote a variable is when using the string bitwise operators on something that happens to have a cached numeric value:
(Do the noises in my head bother you?)$ perl -le'$x = "41"; 0+$x; print for ("$x" ^ "3"), ($x ^ "3")' 1 42
|
|---|