Syrkres has asked for the wisdom of the Perl Monks concerning the following question:
And I have a subroutine called location, I would like to determine if the key is a valid sub (may not as it is input data) and if it is call it.%sample = ( location => .somedata.);
I could hard code the keys into some type of Switch code that calls the proper subroutine, but that means I need change that every time I add a new handler (subroutine). I was hoping to just add new subroutines without changing the core flow of the application.foreach $key (keys %sample) { &$key($sample{$key}) if ($key <is a valid name of a subroutine>); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Subroutines reference from data
by chip (Curate) on Mar 22, 2004 at 23:02 UTC | |
by tinita (Parson) on Mar 22, 2004 at 23:29 UTC | |
by Syrkres (Sexton) on Mar 22, 2004 at 23:24 UTC | |
|
Re: Subroutines reference from data
by waswas-fng (Curate) on Mar 22, 2004 at 23:20 UTC |