Hi,
I am sending the values from one method to another method to get the values from xml file based on the inputs.
I am getting the error like::
Variable "$collType" will not stay shared
Variable "$collState" will not stay shared at line 77.
please see the below code and help me out.
-
#!/usr/local/bin/perl -w
-
use XML::Parser;
-
-
my @element_stack; # remember which elements are open
-
my %hash;
-
-
main();
-
-
sub main {
-
my $collType="A";
-
my $collState="AE";
-
my $custName="Robin";
-
-
parseFile($collType, $collState, $custName);
-
-
my $team = $hash{"Default"};;
-
print "size of hash: " . keys( %hash ) . ".\n";
-
-
my $el=$custName;
-
my @arr;
-
@arr = split(//,$el);
-
foreach(keys %hash)
-
{
-
-
if($_ =~ /$arr[0]/)
-
{
-
$team = $hash{$_};
-
print "$_ team is $hash{$_}";
-
-
}
-
last;
-
-
}
-
print "Team is $team \n";
-
}
-
-
sub parseFile {
-
my($collType, $collState, $custName) = @_;
-
-
-
# initialize the parser
-
my $parser = XML::Parser->new( Handlers =>
-
{
-
Start=>\&handle_start,
-
End=>\&handle_end,
-
});
-
$parser->parsefile("../../extract/unicar/state.team.group.xml" );
-
-
-
# process a start-of-element event: print message about element
-
-
sub handle_start {
-
my( $expat, $element, %attrs ) = @_;
-
-
# ask the expat object about our position
-
my $line = $expat->current_line;
-
-
-
-
# remember this element and its starting position by pushing a
-
# little hash onto the element stack
-
push( @element_stack, { element=>$element, line=>$line });
-
if($element eq "StateTeamGroup" || $element eq "StateTeam" || $element eq "State"){
-
-
if( %attrs ) {
-
-
if($attrs{"CollType"} eq $collType and $attrs{"State"} eq $collState){ ## getting the error here
-
print "$collType and $collState *********\n";
-
$hash{ $attrs{Letters} } = $attrs{Team}
-
}
-
}
-
-
}
-
-
-
}
-
-
-
# process an end-of-element event
-
#
-
sub handle_end {
-
my( $expat, $element ) = @_;
-
-
-
}
-
-
}
-
And my xml file will be like this:
-
<StateTeamGroup>
-
<StateTeam>
-
-
<State CollType="A" Comment="Military addresses" Letters="Default" State="AE" Team="TEAM3"/>
-
<State CollType="A" Comment="Military addresses" Letters="ABCD" State="AE" Team="TEAM2"/>
-