Aliasing or Linking a 2nd-level hash with another

I have a hash of hashes of hashes..
The setup is such: $UserDB->{'SomeMember'}->{'Points'} = 1326;
But, SomeMember has both the username SomeMember and GenericUser (lame example)

I need all accesses to one or the other to be reflected in both.. (Reads and writes)
I was thinking *UserDB->{'SomeMember'} = $UserDB->{'GenericUser'}, but that didn't work for me.
LVL 1
Craz3dAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
mkatmonkeyConnect With a Mentor Commented:
Invariable, most languages generate pointers confusion. Perl calls them references, but the confusion is just the same. The code below should do what I think you want. At least it demonstrates the concept.


my $UserDB = {};
$UserDB->{'SomeMember'} = {'Points'=>1326};
 
#Note this coppies the pointer/reference instead of the entire hash
$UserDB->{'GenericUser'} = $UserDB->{'SomeMember'};
 
$UserDB->{'GenericUser'}->{'Points'} += 2;
 
print $UserDB->{'SomeMember'}->{'Points'}; #outputs 1328

Open in new window

0
 
Craz3dAuthor Commented:
Worked fantastically. Thanks.
0
All Courses

From novice to tech pro — start learning today.