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

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

To pass data via a URL you would use something like this:

http://not.dave.org.uk/cgi-bin/script.pl?key1=val1&key2=val2

The parameters are appended to the end of the URL following a question mark (?). Parameters are arranged in key/value pairs where key and value are separated by an equals sign (=). Each pair is spearated from the next with an ampersand (&). Note that certain characters (including ?, = and & for obvious reasons) cannot be used in a URL and must therefore be encoded.

Within the CGI program, extracting the parameters is very easy as long as you use CGI.pm. Not using CGI.pm is dangerous as CGI parameter extraction is a tricky business and very easy to get wrong. Using CGI.pm, you can just write code like this:

#!/usr/bin/perl -w use strict; use CGI qw(:standard); print header(-type => 'text/plain'); foreach (param) { print "Parameter $_ is ", param($), "\n"; }

Note that it is perfectly legal to have multi-valued CGI parameters, like this:

key1=val1&key2=val2a&key2=val2b

In this case the param function will return a list when asked for parameter key2. In this case the sample code above will break.

Get more info on this from perldoc CGI or Lincoln Stein's book The Official Guide to Programming with CGI.pm.

--
<http://www.dave.org.uk>

European Perl Conference - Sept 22/24 2000, ICA, London
<http://www.yapc.org/Europe/>

In reply to Re: Passing Variables in CGI by davorg
in thread Passing Variables in CGI by drujax

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (2)
As of 2024-04-25 02:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found