LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-26-2001, 03:43 PM   #1
phek
Member
 
Registered: Jul 2001
Location: California, US
Distribution: Slackware
Posts: 196

Rep: Reputation: 30
Question error printing array's


OK, im new to perl but, in this script its just basic, putting items into an array and printing them. Now it works fine if i execute it from the console but, when i try to run it from my web browser, it gives me an internal server error. From what i can tell, the cgi can't print more than 2 items in an array, but i'm not sure where to go from there. Well heres my script:

#!/usr/bin/perl
#
# Fun with array's
#
#########################################################
# Create 2 arrays, food and music
@food = ("apples", "pears", "eels");



#print "$food[2]\n"; #print the third object in food array
print "@food\n"; #print all objects in food array

push(@food, "eggs"); #add eggs to the end of food array
print "@food\n"; #print all objects in food array

$grub = pop(@food); #pop returns and removes the last object in an array
print "$grub\n"; #prints $grub
print "@food\n"; #prints all objects in food array

$f = @food; #value of $f is the number of items in the array
print "$f\n"; #print the amount of items in the array food
$f = "@food"; #value of $f is each item of array with a seperatin space
print "$f\n"; #print objects in food array

$a = 1;
$b = 2;
$c = 3;
$d = 4;

($a, $b) = ($c, $d); #same as $a=$c and $b=$d
print "$a $b $c $d\n"; #prints
($a, $b) = @food; #$a and $b equal the first 2 items of @food
print "$a $b\n"; #prints
($a, @somefood) = @food; #$a is the first item of @food, @somefood is the rest
print "$a, @somefood\n"; #prints
(@somefood, $a) = @food; #@somefood is @food and $a is undefined
print "$a, @somefood\n"; #prints
print $#food. "\n"; #prints the last index of @food


and the error i recieve in my apache error_log is:
[Wed Sep 26 12:22:38 2001] [error] [client 10.1.1.143] malformed header from script. Bad header=eels: /www/cgi-bin/test2.cgi

Now, I've taken the "eels" out of the @food array and it works fine with only 2 items instead of 3, but if I add it back in, add something else back in, or try to use the function push to add eels, it gives me the error.

anyone have any ideas? I kind of figure it may be something with my apache server i need to change since the code runs fine from console.

thanks
phek
 
Old 06-04-2002, 03:29 PM   #2
notsoevil
Member
 
Registered: May 2001
Location: Louisville, Kentucky, USA
Distribution: RedHat ES
Posts: 120

Rep: Reputation: 15
You are not printing a Content-type header, which is required for a browser to display content.

Your very first print statement should be the Content-type, as such:

Code:
#!/usr/bin/perl -w

use strict;
print "Content-type: text/plain\n\n";
 #blah blah blah rest of script
Also, though not NECESSARY for this script, please always use '-w' and 'use strict' -- you'll be happier in the long run.

EDIT: Damn, I really need to pay attention to post age -- the question was from 2001! Well, at least an answer is documented for future reference, eh?

Last edited by notsoevil; 06-04-2002 at 03:31 PM.
 
Old 06-05-2002, 06:59 AM   #3
vfs
Member
 
Registered: Apr 2002
Location: Brazil
Distribution: Slackware
Posts: 184

Rep: Reputation: 30
And, when you

use strict;

declare variables with 'my()', like:

my @array;

for my $i (@ARGV) { ... }

and so...

vfs
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Java Array's.... Making An array bigger??? Tru_Messiah Programming 11 08-17-2016 01:45 PM
Printing trouble (Error: client-error-not-possible) Viro Linux - Hardware 2 03-12-2005 02:25 PM
printing error mms_master Linux - Hardware 1 03-19-2004 08:22 PM
printing error calble Linux - Software 7 10-15-2003 04:34 PM
error printing PDF bartgymnast Linux - Software 0 04-14-2003 02:55 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:01 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration