Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Very odd behavior assigning Time::Piece object to hash reference inside of an object

by tangent (Vicar)
on Mar 24, 2016 at 02:14 UTC ( #1158677=note: print w/replies, xml ) Need Help??


in reply to Very odd behavior assigning Time::Piece object to hash reference inside of an object

The behaviour you are seeing is actually a feature of Data::Dumper - the $VAR1->{'polished_data'}{'start'} is simply pointing to the first occurrence of what is exactly the same thing. It does this with all references:
use Data::Dumper; use Time::Piece; my $tp = gmtime; my @array = (200,400); my $data = { 'one' => { 'tp' => $tp, 'array' => \@array, }, 'two' => { 'tp' => $tp, 'array' => \@array, }, }; print Dumper $data; Output: $VAR1 = { 'one' => { 'array' => [ [ 200, 400 ] ], 'tp' => bless( [ 35, 2, 2, 24, 2, '116', 4, 83, 0, 1458784955, 0 ], 'Time::Piece' ) }, 'two' => { 'array' => $VAR1->{'one'}{'array'}, 'tp' => $VAR1->{'one'}{'tp'} } };
To prevent it from doing that you can set Deepcopy:
use Data::Dumper; $Data::Dumper::Deepcopy = 1; ... Output: $VAR1 = { 'one' => { 'array' => [ [ 200, 400 ] ], 'tp' => bless( [ 48, 10, 2, 24, 2, '116', 4, 83, 0, 1458785448, 0 ], 'Time::Piece' ) }, 'two' => { 'array' => [ [ 200, 400 ] ], 'tp' => bless( [ 48, 10, 2, 24, 2, '116', 4, 83, 0, 1458785448, 0 ], 'Time::Piece' ) } };
  • Comment on Re: Very odd behavior assigning Time::Piece object to hash reference inside of an object
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: Very odd behavior assigning Time::Piece object to hash reference inside of an object
by nysus (Parson) on Mar 24, 2016 at 13:37 UTC
    Thank you for clearing this up.

    $PM = "Perl Monk's";
    $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate";
    $nysus = $PM . ' ' . $MCF;
    Click here if you love Perl Monks

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1158677]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2022-05-24 18:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (84 votes). Check out past polls.

    Notices?