Home: Perl Programming Help: Intermediate:
array push/pop is only 1 element dept in cgi



ningji
User

May 1, 2014, 6:53 PM


Views: 9794
array push/pop is only 1 element dept in cgi

i have a very simple perl cgi in ubuntu 12.04 environment in arm processor.

my @array = (0);
push @array, 100;
# print array saying : 0, 100

push @array, 200;
#print array saying : 0, 200
.....
my $v = pop @array;
print $v;

the result is always 0.

Another simple script testing push/pop without cgi is fine.

What could be wrong pls ?


BillKSmith
Veteran

May 1, 2014, 9:12 PM


Views: 9744
Re: [ningji] array push/pop is only 1 element dept in cgi

It is not likely that anything is wrong with push or pop. I recommend that you try to debug this problem by placing unique print statements immediately before and after each push and pop of your cgi script. Run the script in the debug environment. Where does it go wrong?

Code
use strict; 
use warnings;
my @array = (0);

print "\n<dbg>before push 100: @array\n";
push @array, 100;
print "\n<dbg> After push 100: @array\n";
#
#
#
#
print "\n<dbg>before push 200: @array\n";
push @array, 200;
print "\n<dbg> after push 200: @array\n";
#
#
#
#
print "\n<dbg>before pop: @array\n";
my $v = pop @array;
print "\n<dbg>after pop; @array\n";
print "v = $v\n";


EXPECTED OUTPUT:

Code
<dbg>before push 100:  0 

<dbg> After push 100: 0 100

<dbg>before push 200: 0 100

<dbg> after push 200: 0 100 200

<dbg>before pop: 0 100 200

<dbg>after pop; 0 100
v = 200

Good Luck,
Bill