Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Your problem is very simple. All I had to do was look for the one place you have 'no strict' and dig.

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:

# 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; }
That should work. :-)

------
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.


In reply to Re: Tie-ing hashes clobbers data by dragonchild
in thread Tie-ing hashes clobbers data by Dave05

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (8)
As of 2024-04-25 11:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found