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?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: hash reference to itself
by dave_the_m (Monsignor) on Aug 02, 2016 at 17:41 UTC | |
by ExReg (Priest) on Aug 02, 2016 at 18:15 UTC | |
Re: hash reference to itself
by Anonymous Monk on Aug 02, 2016 at 17:09 UTC | |
by ExReg (Priest) on Aug 02, 2016 at 17:19 UTC | |
by ikegami (Patriarch) on Aug 02, 2016 at 17:56 UTC | |
by ExReg (Priest) on Aug 02, 2016 at 18:14 UTC | |
Re: hash reference to itself
by VinsWorldcom (Prior) on Aug 02, 2016 at 17:11 UTC | |
by Your Mother (Archbishop) on Aug 02, 2016 at 18:41 UTC | |
by VinsWorldcom (Prior) on Aug 02, 2016 at 20:01 UTC | |
by Your Mother (Archbishop) on Aug 02, 2016 at 21:22 UTC | |
by ExReg (Priest) on Aug 02, 2016 at 17:30 UTC | |
Re: hash reference to itself
by talexb (Chancellor) on Aug 02, 2016 at 17:05 UTC | |
by ExReg (Priest) on Aug 02, 2016 at 17:25 UTC |
Back to
Seekers of Perl Wisdom