in reply to Re^3: How to conditionally execute a subroutine defined as hash value
in thread How to conditionally execute a subroutine defined as hash value
Not sure i like the lock-in you get with the anon sub approach. I would make the config hash have both the sub references and the options references -- that way if you ever needed to override the options, it's a bit cleaner
.... my $calls => { A => { sub_ref => \&print_A, config_ref => { ... } }, B => { sub_ref => \&print_B, config_ref => { ... } } }; my $test = 'A'; my $sub = $calls->{$test}{sub_ref}; my $config = $calls->{$test}{config_ref}; $sub->( $config );
-derby
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^5: How to conditionally execute a subroutine defined as hash value
by BrowserUk (Patriarch) on Apr 02, 2014 at 11:44 UTC |
In Section
Seekers of Perl Wisdom