Heylo all, did some searching and couldn't find the answer I was hoping for, so just checking to see if there is a way to do what I want.
I have input data stored in a Hash that was parsed from an XML structure, the keys are the element tag of the structure, so what would I like to do is call a function based on the key value.
For example, if I have the following
%sample = ( location => .somedata.);
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.
foreach $key (keys %sample) {
&$key($sample{$key}) if ($key <is a valid name of a subroutine>);
}
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.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.