I'm parsing an XML file using XML:Parser, with the Style set to Subs. What this means is that, when the parser hits <name> it calls the sub 'name'. When it hits </name> it calls the sub 'name_' . I'm using these subs to turn state variables ($state{name}), on and off so that the char_handler knows where to dump the text held between the tags. The problem is that I'm having to write the start and end subroutine for every tag, and they only differ in the name of the state variable.
My question is this : is there any way of generating a subroutine for every element of an array. Thus, if I have an array @tags=(name, gender, address) is there a way of generating the subs name, name_, gender, gender_, description, description_, where each start subroutine turns a state variable named after the tag on, and the end subroutines turn it off ?
Any aid in pursuing the goal of elegance would be greatly appreciated.
PaulIn reply to generating subroutines from array variables by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |