in reply to Using the same hashes as different object variables

Your code doesn't show what %orig_graph is, but I assume you're calling new as ->new(\%orig_graph).

The problem is, you now have two references to the same data. You'd need to copy the data. Perhaps deep-copy the data, but that will depend on your requirements. Copying a hash is trivial:

my %copy = %original;
To make a deep copy, use Data::Dumper (with Purity = 1) and eval the result.

Replies are listed 'Best First'.
Re^2: Using the same hashes as different object variables
by mrguy123 (Hermit) on Jan 20, 2010 at 12:38 UTC
    Thanks for your reply
    I think I do need a deep copy (my original hash also has arrays inside).
    Can you give me a bit more info on how to use the Data:Dumper for a deep copy? I usually just use it for displaying a hash

      You could also use dclone() from Storable to make a deep copy of your data.

      my $hash = eval Data::Dumper->new([{foo => 1, bar => 2}])->Purity(1)->Dump;