Perl: constants and compile-time vs runtime hash lookups?
Clash Royale CLAN TAG #URR8PPP Perl: constants and compile-time vs runtime hash lookups? In Perl 5.26, constant-based hash lookups appear to be resolved at compile-time, not runtime. How can I enforce it to be resolved at runtime? Consider the following reduced testcase, boiled down from a hash-based state-machine I was trying to write, where the key is the state identifier and the value is the state function. use constant { STATE_1 => 1, STATE_2 => 2, }; my %fsm; %fsm = ( STATE_1, sub { $fsm{STATE_2}->(@_); return STATE_2; }, STATE_2, sub { return STATE_1; } ); my $state = STATE_1; $state = $fsm{$state}->(); Note that in STATE_1 , I'm trying to call the STATE_2 function. STATE_1 STATE_2 However, at runtime I get this: Can't use an undefined value as a subroutine reference at ./self-reference-hash.pl line 15. Which indicates that the $fsm{STATE_2}->(@_); line in STATE_1 is undefined. And indeed, at the time where...