http://qs321.pair.com?node_id=1169014

ExReg has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to figure out if it is possible for a hash value to reference a key value in the same hash. As a much simplified example, suppose I have the following:

use strict; my %hash = ( name => "foo", code => sub{ print "name: ", "foo", "\n"; }, ); $hash{code}->(); _____ name: foo

"foo" is the value of the name key and is also in the code subroutine. Is it possible to have a hash refer to itself with something like

use strict; my %hash = ( name => "foo", code => sub{ print "name: ", $hash{name}, "\n"; }, ); $hash{code}->();

Obviously this syntax does not work, but is there a way to do this?