I'm sure there is a more accurate name for what I am trying to do, so this title will have to do. More or less, I've got a package that I am storing the state using Data::Dumper and loading it back in with eval. You're probably already starting to cringe ;-)

Here is a short, simplified snippet that displays what I've got so far and what I need to know how to fix. It will probably only be one line. (This is just a brief overview of what I'm trying to do; the real code is running with strict, etc.)
my $test = Test->new(123); $test->change(345); print $test->{id}; # Should print 345 package Test; sub new { bless{ id=>$_[1], } } sub change { my($self,$id) = @_; my $t2 = Test->new($id); $self = $t2; # This line is broke }

Any ideas on how to obtain the desired effect? On a side note, is storing states with Data::Dumper so terrible that I should do something else?

Thanks,
-billyak

In reply to Object Swaps by billyak

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.