This is a boiled-down version of a bit of sofware where I discovered I
apparently don't fully understand variable scopes. In the following,
the "our" variable $request will be undef in the unnamed Start
subroutine if I just try to define it with "my". Apparently using it in
foreach is the cause, but I am a bit unclear on how/why this happens?
Anyone have pointers to web pages etc where this is spelled out?
Also, using a global variable here is obviously kludgy. Forgive me.
----
#!/usr/bin/perl
use strict;
use warnings;
use XML::Parser::Lite;
my $xmldata = <<'END';
<response>
<record value="first"/>
<record value="second"/>
</response>
END
our $request;
my $parser = XML::Parser::Lite->new(
Handlers => {
Start => sub {
shift;
# Only process "record" blocks
return unless shift eq 'record';
# Load parsed xml into hash for access
my %data=@_;
print $request,"\t",$data{'value'},"\n";
},
},
);
foreach $request ( qw(datarequest) ) {
# Here we would retrieve xml data from SOAP using $request etc
$parser->parse($xmldata);
}
--
/* * * Otto J. Makela <
o...@iki.fi> * * * * * * * * * */
/* Phone:
+358 40 765 5772, ICBM: N 60 10' E 24 55' */
/* Mail: Mechelininkatu 26 B 27, FI-00100 Helsinki */
/* * * Computers Rule 01001111 01001011 * * * * * * */