Bernd Prager wrote: >> >> Why dont you just define the function outside and call them from inside >> your master function >> >> Bernd Prager wrote: >> > >> > I run into a problem and would appreciate some help. >> > >> > I'd like to write a subroutine that parses an XML file. >> > I use XML::Parse and one way that works is to define
are you using XML::Parser or XML::Parse? i didn't know there is a XML::Parse. anyway, I imagine you are using XML::Parser... >> > subroutines with the name of an XML tag and every appearance >> > of that tag calls the appropriate subroutine. >> > >> > Since I want to have this procedure entirely encapsulated in >> > my funtion I end up defining nested subroutines: >> > >> > sub myParse { >> > my $content; >> > >> > sub myXMLtag { >> > (... do something with $content...) >> > } >> > >> > } >> > >> > Now I'm getting error messages "Variable "$content" will not stay >> > shared". >> > >> > I read something about anonymous functions to prevend this error but >> > I can't do that here since XML::Parse requires the function names >> > the same as the XML tags. > > The reason is that some XML tags conflict with other naming conventions I > use. And it is not very expressive to have function names that are called > "value" and "item". the tag of the XML has nothing to do with what you associate your callback functions! you don't have to use the same name for your callback function as the name of the XML tag. the idea of using a callback is the idea that you can use any function YOU define for the action. there shouldn't be any conflict at all. for example: <!-- simple XML file --> <?xml version="1.0" encoding=?utf-8"> <something> <hi> hi </hi> <hello> hello </hello> </somthing> and then: #!/usr/bin/perl -w use strict; use XML::Parser; my $xml = new XML::Parser(Hanlders => {Start => \&start, End => \&end, Char => \&char}); $xml->parse('xml.file'); sub start{ print "Encounter start tag: $_[1]\n"; } sub end{ print "$_[1] tag end\n"; } sub char{ print "I get char: $_[1]\n"; } __END__ notice i don't have to name my callback like 'hi','hello', etc so that they match the name of the XML tags. i might have miss something but if you are afraid that the callback has to match the name of the XML tag, you don't. david > > But I did find a way to prevend the error message. I just have to use full > qualified variable names like "$myParse::content". That works for me. :)) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]