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

Any1 knows what it is?
when perl -c no syntax errors
when perl -w getting this error:
#Undefined subroutine &main::param called at bonus.pl line 14.
it supposed to come up with:
(offline mode: enter name=value pairs on standard input)

Here is the code form the book:

#!D:/Perl/bin/perl #bonus.pl - calculates a bonus amount and creates a dynamic Web page #that contains form data and a bonus amount print "Content-type: text/html\n\n"; use CGI qw(:sandard -debug); #prevent Perl from creating undeclared variables use strict; #declare variables my ($name, $sales, $rate, $bonus); #assign values to variables $name = param('Salesperson'); $sales = param('Sales'); $rate = param('Rate'); #calculate bonus amount $bonus = $sales * $rate; #create Web page print "<HTML>\n"; print "<HEAD><TITLE>Patton Industries</TITLE><BASEFONT SIZE=5></HEAD>\ +n"; print "<H1>Bonus Calculation</H1>\n"; print "<BODY>\n"; print "Salesperson: $name<br>\n"; print "Your bonus is: $bonus<br>\n"; print "You entered a sales amount of $sales and\n"; print " a bonus rate of $rate <br>\n"; print "</BODY>\n"; print "</HTML>\n";

Edit: Removed <br> tags from code, per request. larsen

Replies are listed 'Best First'.
Re: Undefined subroutine &main error
by chromatic (Archbishop) on Mar 07, 2003 at 18:53 UTC

    You misspelled :standard, so CGI didn't export param into your namespace.

Re: Undefined subroutine &main error
by Enlil (Parson) on Mar 07, 2003 at 18:57 UTC
    If you change this line: use CGI qw(:sandard -debug); to this: use CGI qw(:standard -debug); (standard misspelled). The problem should go away.

    -enlil

      many THNX!!! works like magic now!!
Re: Undefined subroutine &main error
by cfreak (Chaplain) on Mar 07, 2003 at 20:10 UTC

    Just want to clarify something real fast. I believe that perl -c filename will only check for syntax errors, while  perl -w will get runtime warnings. That's why you don't get an error with -c, because an undefined sub isn't going to be an error until runtime.

    You can mix the parameters as well by doing perl -cw, that will give you both.

    Lobster Aliens Are attacking the world!
      in reply to the last coment from cfreak
      >You can mix the parameters as well by doing perl -cw, that will give you both.<

      so, i fixed the spelling of "use CGI qw(:sandard -debug);"
      and it worked fine.
      your suggestion of using 'perl -cw' (tried -wc also) checking only syntax and not reaching runtime.
      "...\exc\bonus>perl -wc bonus1.pl
      bonus1.pl syntax OK" same return from -cw.
      Thnx anyway.
Re: Undefined subroutine &main error
by skki (Initiate) on Mar 07, 2003 at 19:27 UTC
    many, many THNX!!! guys.
    works like magic now!