![]() |
|
Problems? Is your data what you think it is? | |
PerlMonks |
comment on |
( #3333=superdoc: print w/replies, xml ) | Need Help?? |
I'm currently writing a program which passes some user information around in a hash. In one of the subroutines of one of my files, the address of $_ is the same as the address of some of my data
\$_ = SCALAR(0x401ba594) \$u->{loc} = SCALAR(0x401ba594) I traced the problem down to this line of code in another file (which calls the above sub) foreach ($u->{loc}) { ... } So my question, how does the scoping apply to $_? I know that it's in package 'main', so it's global throughout my program (even across separate files). Can I make it local temporarily, or is there some other trick I can use? I'd like to avoid something like (foreach $a ($u->{loc})) because I actually have that foreach line in many spots, with lots of pattern matching, so it keeps my code cleaner to use $_. Is copying $u->{loc} into a temp variable prior to the foreach perhaps the best solution? Thanks for any help, In reply to $_ scoping issues by swkronenfeld
|
|