ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.