CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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

 



ningji
Novice

May 1, 2014, 6:53 PM

Post #1 of 2 (7570 views)
array push/pop is only 1 element dept in cgi Can't Post

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

Post #2 of 2 (7520 views)
Re: [ningji] array push/pop is only 1 element dept in cgi [In reply to] Can't Post

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

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives