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

I want to execute a perl script and pass a parameter. In the script, I want to capture the parameter (and validate it). If not valid, then I will handle by printing a message and exiting. I have read similar petitions and suggestions and tried them, but cannot get it to work (HELP!). See below for a code snippet:
#make the call:
***Below is the snippet from myscript.cgi: #!/usr/bin/perl -w print "Content-type: text/html\n\n"; $myvalue = param("test"); print "<HTML>\n"; print "<BODY BGCOLOR=#FFFFFF>\n"; print "<CENTER>\n"; print "myvalue: $myvalue"; print "</CENTER>\n"; print "</BODY></HTML>";

Replies are listed 'Best First'.
Re: passing and using param
by Ovid (Cardinal) on Oct 07, 2002 at 00:36 UTC

    You may wish to take a look at my CGI course. It will provide you with a lot of information and should make your Web development life easier.


    Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

Re: passing and using param
by moxliukas (Curate) on Oct 06, 2002 at 23:16 UTC

    Well, I think you forgot use CGI;

    Your code would look (untested):

    #!/usr/bin/perl -w use strict; use CGI qw/:standard/; print header; my $myvalue = param("test"); print <<EOS; <BODY BGCOLOR=#FFFFFF> <CENTER> myvalue: $myvalue </CENTER> </BODY></HTML> EOS

    Note that I have replaced a bunch of your print statements by using a HEREDOC syntax. Of course, you can do it with a few prints, but it very much neater this way. Oh, and you might want to use built in CGI functions for generating HTML.. For all your CGI needs, consult CGI manual.

    ...And don't forget to use strict ;)

Re: passing and using param
by varf (Acolyte) on Oct 07, 2002 at 13:50 UTC
    looking at the supplied URL... shouldn't you be testing for param("id") instead of param("test")?
    in addition to use CGI; as mentioned above.