473,513 Members | 2,428 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Getting the error:: Variables will not stay shared

25 New Member
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
1 3956
KevinADC
4,059 Recognized Expert Specialist
That is not an error, it is a warning. Does the script work?
Oct 15 '07 #2

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

Similar topics

1
5012
by: Wayno | last post by:
My php logs are coming up empty. I have done all I can think of, and all that made sense to me. Can someone take a look at my php.ini please and tell me what you think may be the problem. I...
3
2035
by: sarmin kho | last post by:
Hi Pythoners, i have been using a lot of global variables in the python script i am working on. the global variables are shared and used by all various 'definitions' : def name (): global all...
6
4715
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
6
1652
by: Alixx Skevington | last post by:
OK why does the following code work in a Windows form with a crystal report viewer but not in a webform. I get the usual CrystalReports.EngineLogONException logon Failed when this is called in...
11
1322
by: Matt Mercer | last post by:
Hi, I have a simple question about vb .net variables. There is so much info on variables out there I had trouble finding exactly what I am looking for. Here is the question: When I use a...
2
1788
by: Oenone | last post by:
I'm upgrading a DLL from VB6 to VB.NET. The DLL gets called from an ASP.NET web application. In the VB6 code there is a module-level object which stores the context about what the user is doing...
9
3170
by: Randy | last post by:
Hello, I'm having a strange problem. I've got a .NET web app which uses Session variables. Sometime, not all the time, they get cross threaded...that is...one user will have another user's Session...
669
25403
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
2
13638
by: ronchese | last post by:
I'm noticing this since I started developing a website project: my session variables are getting empty! I did a real easy test, and I checked my session variable is getting empty!! What is...
0
7160
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7384
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7537
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7099
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5685
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...
1
5086
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4746
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3222
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
456
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.