Basilides has asked for the wisdom of the Perl Monks concerning the following question:
my $p = new XML::Parser (Handlers => {Start => \&hdl_start(@arr), etc} +);
However, the following seems to be working fine for me (obviously it doesn't do anything, but it shows that the variables are being set from the subroutine), and I'm a bit concerned about why:
Can someone who knows about scope tell me if I'm doing a very bad thing?use strict; use XML::Parser; my ($tag, $name); my $p = new XML::Parser (Handlers => {Start => \&hdl_start, Default => \&hdl_def}); $p->parsefile('test.xml'); print "$tag, $name\n"; sub hdl_start { my ($p, $elt, %atts) = @_; $tag = $elt; $name = $atts{'name'}; } sub hdl_def { }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Variable scope with XML::Parser
by zby (Vicar) on Mar 17, 2003 at 11:04 UTC | |
by Basilides (Friar) on Mar 17, 2003 at 12:43 UTC | |
by zby (Vicar) on Mar 17, 2003 at 13:03 UTC | |
by dragonchild (Archbishop) on Mar 17, 2003 at 16:22 UTC | |
by grantm (Parson) on Mar 17, 2003 at 19:01 UTC | |
|
Re: Variable scope with XML::Parser
by PodMaster (Abbot) on Mar 18, 2003 at 10:35 UTC |