Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

passing and using param

by Anonymous Monk
on Oct 06, 2002 at 21:19 UTC ( #203210=perlquestion: print w/replies, xml ) Need Help??

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: http://www.test.com/myscript.cgi?id=1234
***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.

    Cheers,
    Ovid

    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.

    HTH.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://203210]
Approved by mr2
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2022-06-30 12:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My most frequent journeys are powered by:









    Results (98 votes). Check out past polls.

    Notices?