I used strict and warning.
And the call of the build_sth('set_to_flag') in another function which is called in the main per script:
I have checked the previous version where I got trapped. I get the code fail when I move the hash outside of function:(continue with previous code) sub somecall{ build_sth('set_to_flag') } somecall();
why the code fail in this case?my %Op = ( set_to_flag => \&write_flag, set_tree => \&write_sets, default => \&do_nothing ); sub build_sth { my ($op_code) = @_; my $op_exec = $Op{$op_code} ; if( defined $op_exec ){ $op_exec->(); }else{ print "Oops\n"; } }
In reply to Re^2: Function reference undef when extract from hash?
by Anonymous Monk
in thread Function reference undef when extract from hash?
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |