Click to See Complete Forum and Search --> : Using the PERL get method


Jabul
12-22-2005, 04:35 PM
This is something that has been holding me back for a while. When using the GET method in perl, what happens when you address a variable in your script that wont always be used in the address?

For Example, if I have the variables $name, $friend, and $number (Im making this all up and this particualr script most likely has no use.)
Now lets say I only want to know my name, so I click on the link script.pl?name=Jabul but when script.pl runs it checks to see the all the variables values. Will it just skip over these statements if they are if then statements?

I know my questions a little hard to understand, but maybe if you think about how most perl forums are setup it would be easier. If your in the index.pl then you can have a forumid varable, a postid and stuff like that. I'm sorry if Im not clear enough... :(

Ultimater
12-22-2005, 04:53 PM
Perl is very easily able to read paremeters with the param method from the CGI module.

FYI, this is called a querystring:

script.pl?name=Jabul

and "name" is called a parameter.

Splitting pages (http://webdeveloper.com/forum/showthread.php?t=89345)

Jabul
12-22-2005, 04:56 PM
I know it can read them, my question is really what does it treat this "parameter" as if its not in the address, does it = 0? Does it not exist? How does it treat ones that it checks for the if of an if then statement that arent in the address bad (Sorry, I know thats a lot and very disorganized)

Nedals
12-22-2005, 07:44 PM
#!/usr/bin/perl -w
use strict;
use CGI;

my $q = CGI->new();

my $name = $q->param('name');
my $friend = $q->param('friend');
my $number = $q->param('number');

Items not in the 'query string' will, in fact, be 'undefined' but in Perl you can treat them as '=0' or a 'false value'
ie:
if (!$name) { print "name is not there\n"; }