Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
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.
Paul
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: generating subroutines from array variables
by Kanji (Parson) on Aug 17, 2003 at 16:55 UTC | |
|
Re: generating subroutines from array variables
by mattriff (Chaplain) on Aug 17, 2003 at 15:56 UTC | |
by esh (Pilgrim) on Aug 17, 2003 at 17:16 UTC | |
|
Re: generating subroutines from array variables
by gwadej (Chaplain) on Aug 18, 2003 at 02:21 UTC | |
|
Re: generating subroutines from array variables
by bunnyman (Hermit) on Aug 18, 2003 at 20:53 UTC | |
by bemused (Initiate) on Aug 21, 2003 at 10:54 UTC |