I'm trying to return a reference to a hash from a string value but the results depends on the order of when the hash and sub are defined.
Snippet 1:
my $uid = { '199' => 'Twister', '396' => 'Khorus', '450' => 'Ling', '555' => 'Sage' };
sub href { eval "\$$_[0]" }
print Dumper href('uid');
Output of snippet 1:
$VAR1 = {
'199' => 'Twister',
'396' => 'Khorus',
'450' => 'Ling',
'555' => 'Sage'
};
Snippet 2:
sub href { eval "\$$_[0]" }
my $uid = { '199' => 'Twister', '396' => 'Khorus', '450' => 'Ling', '555' => 'Sage' };
print Dumper href('uid');
Output of snippet 2:
$VAR1 = undef;
It shouldn't matter if the sub is defined before or after the hash but it does. What am I missing?