Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Couple of points. A cyclic or self-referential structure will break your Tie. Second in the _write sub you are making a _copy_ of the hash. This may or may not be what you want to do.

But I think the heart of your problem is here:

print FH Data::Dumper->Dump([\%data], ['*data']);
and here
my $ret = do $file
This line sets the $ret value to be equal to the glob *data which was just overwritten by you. (ok, so you ignore the $ret and use the global var \%data, but that was just overwritten so... Same dif.) So its the copy semantics in the _write and _read subs that are causing you trouble. Change them to use scalar refs and not globs and the problem will go away. Oh and lose the shallow copy in _read its misleading and unnecessary.

UPDATE

A question: Why are you mixing proper method calls and procedural calls? _write() is a method, but you call it as a procedure. This means it wont be overidable in a subclass...

sub DESTROY { _write ($_[0]) } #not overidable!

Yves / DeMerphq
---
Writing a good benchmark isnt as easy as it might look.


In reply to Re: Tie-ing hashes clobbers data by demerphq
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 examining the Monastery: (9)
As of 2024-04-19 06:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found