Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I send a variable to sub(ex.36)"script.cgi?action=addoffers?36"

Status
Not open for further replies.

PasPy

Programmer
May 16, 2002
11
CA
How do I send a variable to a subroutine(ex.36) "script.cgi?action=addoffers?36"
Hi,
I want to know how to send a variable to a Subroutines,

exemple: .../exemple.cgi?action=addoffers?36 (where 36 is the variable)


thanks
 
From the 'Perl in a Nutshell' book:

4.7.1 Calling Subroutines

The ampersand (&) is the identifier used to call subroutines. Most of the time, however, subroutines can be used in an expression just like built-in functions. To
call subroutines directly:

name(args); # & is optional with parentheses
name args; # Parens optional if predeclared/imported
&name; # Passes current @_ to subroutine

To call subroutines indirectly (by name or by reference):

&$subref(args); # & is not optional on indirect call
&$subref; # Passes current @_ to subroutine

4.7.2 Passing Arguments

All arguments to a subroutine are passed as a single, flat list of scalars, and return values are returned the same way. Any arrays or hashes passed in these lists
will have their values interpolated into the flattened list.

Any arguments passed to a subroutine come in as the array @_.

You may use the explicit return statement to return a value and leave the subroutine at any point.

Let us know if you have any further questions.

- Rieekan
 
If you have a peice of CGI like this,
Code:
#!/usr/local/bin/perl -T
use strict;
use CGI;
my $obj = new CGI;
my $addoffers = $obj->param('addoffers');
print $obj->header, 
	$obj->start_html, 
	"AddOffers: $addoffers",
	$obj->end_html;

If that cgi is at /path_to/server_root/cgi-bin/example.cgi,
you can call it and pass in a var like this,
Code:
[URL unfurl="true"]http://www.your_server.com/cgi-bin/exemple.cgi?addoffers=36[/URL]
--------------------------
You can also do it with a 'post', if you need. As long as yoururl is fairly short (< 256 bytes, i think ) a 'get' will work. 'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top