in reply to Tie-ing hashes clobbers data
You're constantly setting (and re-setting) a global variable called %data. Since you give a reference to this back to your TIEHASH function, any time you write into (or over) %data, that will appear in every single instance of this TIEHASH you have.
Now, a good solution would be to not return a reference, but return a hash. Then, take a reference to the copied hash (which is now not called %data), and you're fine.
A better solution would be this:
That should work. :-)# Untested change!!! sub _read { # still need to deal with race conditions my $file = shift; return undef unless -f $file; our %data; unless (my $ret = do $file) { warn "couldn't parse $file: $@" if $@; warn "couldn't do $file: $!" unless defined $ret; } return \%data; }
------
We are the carpenters and bricklayers of the Information Age.
Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.
|
|---|