in reply to Accessing Multilevel Hash Values
Of course... if you are only going to be accessing sockets by the "name", then you should consider using that as the key and storing the socket key somewhere else. But that is if name will be the only way you key in.$socket = 'socketa'; $connections{$socket} = {}; $connections{$socket}{name} = 'Bob'; $sockets{Bob} = $socket; #to access it $connections{$sockets{Bob}};
The other way is to write a for loop to iterate through the hash and find it
Also, when accessing a hash value you should prepend the hash with a $, not a %, as so:my $socket; my $name = 'Bob'; for my $key (keys %connections) { if($connections{$key}{name} eq $name) { $socket = $_; last; } } print "$socket is the socket for $name\n";
See Tye's References Quick Reference$connections{socket}{username} = "Bob";
- Ant
- Some of my
best work - (1 2 3)
|
|---|