On Wed, 2002-06-12 at 23:30, W. Huang wrote: > Hi, > > I have a refence to a hash, which is $hashref. I want to print out the > name of the hash ( which is "%hash" ) from $hashref, but don't know how. > Could you please help? thanks! > > #----- > %hash= { > apple => "red", > bana => "yellow", > }; > $hashref =\%hash; > print ?hashref; > #----- > > Carlos
In general, when you want to do something like this ("I want to know the name of this variable") it means you do not have a sufficient level of abstraction. The classic example is the use of many scalars name $x1, $x2, $x3 instead of just using an array. This is the same sort of problem except you need a nested hash structure instead of an array. To use your example: #note these should be parens not braces #braces create a hash reference not a hash my %hash_of_data = ( apple => "red", bana => "yellow", ); my %hash_of_hashes = ( hash_of_data => \%hash_of_data, ); print "$_\n" for keys %hash_of_hashes; print "$hash_of_hashes{hash_of_data}{apple}\n"; the preceding code should print (but might not since I didn't test it): hash_of_data red -- Today is Prickle-Prickle the 18th day of Confusion in the YOLD 3168 P'tang! Missile Address: 33:48:3.521N 84:23:34.786W -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]