APM: global scope array doesn't seem to be global
jeremy
jeremyb at univista.com
Tue May 6 21:05:09 CDT 2003
Mongers,
I've been working on a CGI script that does quite bit of syncing,
parsing and rendering of content from other http servers. The script is
split into several sub routines. At the beginning of the script I
declare several vars, arrays and hashes that are referenced by the
various subs. The array I'm having problems with is call @repeat.
@repeat is declared at the top of the script before any subs get
called. It gets populated by a sub called GEN_CONTENT(). GEN_CONTENT()
calls REPEAT_CONTENT() which does some content rendering with the values
in the @repeat array, among others.
THE SYSTEM:
Red Hat 7.1
Linux 2.4.2-2 #1 Sun Apr 8 20:41:30 EDT 2001 i686 unknown
v5.6.0 built for i386-linux
THE PROBLEM:
Just prior to calling REPEAT_CONTENT() from GEN_CONTENT() the @repeat
array is, indeed, populated with what I expect. Next, when I print out
the elements of @repeat from within REPEAT_CONTENT(), all it contains is
a single blank line. After REPEAT_CONTENT returns, I check the elements
of @repeat again from GEN_CONTENT() and everything is as it should be
just like it was prior to entering into REPEAT_CONTENT().
The problem is obviously that @repeat is not global in scope, I just
don't know why. I would expect this behavior if I had not declared
@repeat at the beginning of the script, but I did. Furthermore it
doesn't get declared again anywhere inside GEN_CONTENT(), which might
cause this problem. The script is 1050 lines long so I'll not be
including it here!
Any ideas on what the problem is?
Here's the snippet of code I describe and the top of the script where
the declarations are:
575 print "before REPEAT_CONTENT( task )\n";
576 foreach( @repeat ){
577 print "====== $_\n";
578 }
579
580 &REPEAT_CONTENT( 'task' );
581
582 print "After REPEAT_CONTENT( task )\n";
583 foreach( @repeat ){
584 print "====== $_\n";
585 }
Here's the beginning snippet from REPEAT_CONTENT where I check the
content of @repeat:
756 sub REPEAT_CONTENT{
757
758
759 ########################### DEBUG
760 if ( $config{ debug } eq 'yes' ){
761 print "\n\n Inside REPEAT_CONTENT( $_[0]$_[1] )\n\n";
762 foreach( @repeat ){
763 print "====== $_ \n";
764 }
765 }
1 #!/usr/bin/perl
2
3 use strict;
4 use LWP::UserAgent;
5 use HTTP::Cookies;
6 use CGI;
7
8 my $config_file = "/etc/owapi/conf/shrinkwrap.conf";
9
10
11 # Not set in the config file ....leave these alone!
12 my $do_sync = undef;
13 my @task_table = undef;
14 my @table_data = undef;
15 my @cal_table = undef;
16 my @eml_elements = undef;
17 my @repeat = undef;
thanks in advance,
Jeremy
More information about the Austin
mailing list