467,876 Members | 1,093 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,876 developers. It's quick & easy.

Getting the error:: Variables will not stay shared

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.


Expand|Select|Wrap|Line Numbers
  1. #!/usr/local/bin/perl -w
  2. use XML::Parser;
  3.  
  4.  my @element_stack;                # remember which elements are open
  5.  my %hash;
  6.  
  7.  main();
  8.  
  9. sub main {
  10.     my $collType="A";
  11.     my $collState="AE";
  12.     my $custName="Robin";
  13.  
  14.     parseFile($collType, $collState, $custName);
  15.  
  16.     my $team = $hash{"Default"};;
  17.     print "size of hash:  " . keys( %hash ) . ".\n";
  18.  
  19.     my $el=$custName;
  20.     my @arr;
  21.     @arr = split(//,$el);
  22.     foreach(keys %hash) 
  23.     {
  24.  
  25.         if($_ =~ /$arr[0]/)
  26.         {
  27.              $team = $hash{$_};
  28.             print "$_ team is $hash{$_}";
  29.  
  30.         }
  31.         last;
  32.  
  33.     }
  34.     print "Team is $team \n";
  35. }
  36.  
  37.  sub parseFile {
  38.  my($collType, $collState, $custName) = @_;
  39.  
  40.  
  41. # initialize the parser
  42. my $parser = XML::Parser->new( Handlers => 
  43.                                      {
  44.                                       Start=>\&handle_start,
  45.                                       End=>\&handle_end,
  46.                                      });
  47. $parser->parsefile("../../extract/unicar/state.team.group.xml" );
  48.  
  49.  
  50. # process a start-of-element event: print message about element
  51.  
  52. sub handle_start {
  53.     my( $expat, $element, %attrs ) = @_;
  54.  
  55.     # ask the expat object about our position
  56.     my $line = $expat->current_line;
  57.  
  58.  
  59.  
  60.     # remember this element and its starting position by pushing a
  61.     # little hash onto the element stack
  62.     push( @element_stack, { element=>$element, line=>$line });
  63.     if($element eq "StateTeamGroup" || $element eq "StateTeam" || $element eq "State"){
  64.  
  65.         if( %attrs ) {
  66.  
  67.         if($attrs{"CollType"} eq $collType and $attrs{"State"} eq $collState)## getting the error here
  68.          print "$collType and $collState *********\n";
  69.             $hash{  $attrs{Letters}  } = $attrs{Team}
  70.         }
  71.         }
  72.  
  73.      }        
  74.  
  75.  
  76. }
  77.  
  78.  
  79. # process an end-of-element event
  80. #
  81. sub handle_end {
  82.     my( $expat, $element ) = @_;
  83.  
  84.  
  85. }
  86.  
  87. }
  88.  
And my xml file will be like this:

Expand|Select|Wrap|Line Numbers
  1. <StateTeamGroup>
  2.   <StateTeam>
  3.  
  4.      <State CollType="A" Comment="Military addresses" Letters="Default" State="AE" Team="TEAM3"/>
  5. <State CollType="A" Comment="Military addresses" Letters="ABCD" State="AE" Team="TEAM2"/>
  6.  
Oct 15 '07 #1
  • viewed: 3673
Share:
1 Reply
KevinADC
Expert 2GB
That is not an error, it is a warning. Does the script work?
Oct 15 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Wayno | last post: by
3 posts views Thread by sarmin kho | last post: by
6 posts views Thread by Peter Frost | last post: by
6 posts views Thread by Alixx Skevington | last post: by
11 posts views Thread by Matt Mercer | last post: by
9 posts views Thread by Randy | last post: by
669 posts views Thread by Xah Lee | last post: by
2 posts views Thread by ronchese | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.