Can anyone help me understand what is going on in this situation?
When I originally wrote this I thought that Perl might store a reference to each variable in $_ so I used $$_++ instead, which only gave me an error ("Modification of read only value"). Then for some reason I removed the extra $ and it it gave me the result I was hoping for. But I still don't understand why this works. I guess what I am asking is why does modifying $_ effect the other variables in the same manner? Can anyone give me some insight?
Thanks
+Cory
Code:
$a = 1;
$b = 2;
$c = 3;
print "$a $b $c\n";
for ($a, $b, $c){
$_++;
}
print "$a $b $c"
Output:
1 2 3
2 3 4
When I originally wrote this I thought that Perl might store a reference to each variable in $_ so I used $$_++ instead, which only gave me an error ("Modification of read only value"). Then for some reason I removed the extra $ and it it gave me the result I was hoping for. But I still don't understand why this works. I guess what I am asking is why does modifying $_ effect the other variables in the same manner? Can anyone give me some insight?
Thanks
+Cory