curtisb has asked for the wisdom of the Perl Monks concerning the following question:

Can anyone tell me what is wrong with this. I have been working on this for hours. I have posted the majority of the script here. It is pretty simple but I'm having a hard time with the array in the return_html sub function. Please help.
#!/usr/local/bin/perl -w #BurgerDog CGI script/HTML use CGI qw(:standard); #\\Declares global varibles and global arrays # $here = param("location"); $name = param("name"); $email = param("email"); $cost = 0; @food = ('', 'plain dog', 'cheese dog', 'big dog'); @fries = ('', 'yes', 'no'); @onionrings = ('', 'no', 'yes'); @drink = ('', 'pepsi', 'coke'); # #\\Start of the HTML page # print header(), start_html("BurgerDog Resturant"), h1("BurgerDog Order + Form"); if (param()) { return_html(); dborder(); cost(); mailout(); }else{ first_page(); } sub first_page #\\Sets up the default html page with blank fields. { print hr(); print start_form(); print p("Location: ", textfield("location")); print p("Name: ", textfield("name")); print p("Email: ", textfield("email")); print p("What type of BurgerDog would you like? ", popup_menu('foo +d', \@food)); print p("Would you like fries with that? ", popup_menu('Fries', \@ +fries)); print p("Would you like Onion Rings? ", popup_menu('OnionRings', \ +@onionrings)); print p("Would you like a drink? ", popup_menu('drink', \@drink)); print p(submit("Submit Order"), reset("Clear Order")); print end_form(), print hr(); } sub return_html #\\Returns a static html page with variable&arr +ay information. { print hr(), start_html(); print p("$name, you placed an order from $here.\n"); print p("And you would like a $food[$index].\n"); print p("$fries, french fries?\n"); print p("$onionrings, onion rings?\n"); print p("A $drink would be nice with that, Thanks!"); print p("Your total is \$$cost\n"); print p("You can be contacted at $email."); print hr(), end_html(); }
Bobby L. Curtis System Administrator

Replies are listed 'Best First'.
Re: Array problem
by Fastolfe (Vicar) on Sep 23, 2000 at 00:07 UTC
    The first element of @food is blank. Since $index is not defined anywhere in your script, Perl will attempt to retrieve the value for $food[0], which is an empty string, which is what you're getting.

    Please consider adding use strict; to the top of your script to turn on Perl's strict variable checking. This would have caught the fact that $index is unused and might have pointed you in the right direction.

RE: Array problem
by bastard (Hermit) on Sep 23, 2000 at 01:11 UTC
    I see your problem and it has nothing to do with arrays.

    You need to pull in the params for the rest of the stuff you're looking for. You did this:

    $here = param("location"); $name = param("name"); $email = param("email");
    And for got the rest:
    $food = param("food"); $fries = param("Fries"); etc...
    You will not need an array for the food param. And like fastolfe mentioned get into the habit of the "use strict" line. (It means you'll have to explicitly pass in variables to the subroutines.)