Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > get variables?

Reply
Thread Tools

get variables?

 
 
Ste (Stefano Russo)
Guest
Posts: n/a
 
      06-28-2004
Hi, i would like to know if is possible to recall a variable passed via
get trought a url.

example:

www.terra32.net/perl/ping.pl?url=www.google.it

How can i recall the variable "url" in the script?

Thanks a lot, excuseme for my bad english..

--
|||
(0.0)
|-------------o00----00o-----------------------------|
|Stefano Alberto Russo - Liceo Oberdan - Trieste |
|www.terra32.net - webmaster @ www.acquariofilia.biz |
|----------------------------------------------------|

 
Reply With Quote
 
 
 
 
Paul Lalli
Guest
Posts: n/a
 
      06-28-2004
On Mon, 28 Jun 2004, Ste (Stefano Russo) wrote:

> Hi, i would like to know if is possible to recall a variable passed via
> get trought a url.
>
> example:
>
> www.terra32.net/perl/ping.pl?url=www.google.it
>
> How can i recall the variable "url" in the script?
>
> Thanks a lot, excuseme for my bad english..


There are two main ways. One is to manually parse the Query String
environment variable. In your example above, your script would have a
variable
$ENV{'QUERY_STRING'} = 'url=www.google.it';

You could manually parse this variable and set the values you need. This
is generally considered a bad idea by most people. The preferred
alternative is to use the ever popular (and standard) CGI module:

use CGI qw/:standard/;

my $site = param('url');


That will automatically parse the query string and set the variable $site
to whatever value the 'url' GET parameter had.

For more information, read the documentation on CGI.pm:
perldoc CGI

Hope this helps,
Paul Lalli
 
Reply With Quote
 
 
 
 
A. Sinan Unur
Guest
Posts: n/a
 
      06-28-2004
Purl Gurl <(E-Mail Removed)> wrote in news:40E066C6.64699ED6
@purlgurl.net:

> $EVN{REQUEST_URI}


What is that ???

> Brigitte Jellinek:
>
> http://rec.horus.at/deadlinks/guestbook/formlib.txt


Hmmm ... looking at that, I am surprised to see:

@k = keys(%in); # I couldn't find a better way of counting
$noin = $#k; $noin++; # entries in %in. do YOU know one?

I never looked into Perl 4, but I am curious: Would

my $k = keys %in;

not have worked with Perl 4?


--
A. Sinan Unur
http://www.velocityreviews.com/forums/(E-Mail Removed) (reverse each component for email address)
 
Reply With Quote
 
A. Sinan Unur
Guest
Posts: n/a
 
      06-28-2004
Purl Gurl <(E-Mail Removed)> wrote in
news:(E-Mail Removed):

> A. Sinan Unur wrote:
>
>> Purl Gurl

>
>> > $EVN{REQUEST_URI}

>
>> What is that ???

>
> A misspelling which you are invited to correct.


I don't need to. You should not post non-working code.

You snipped the context right out:

Purl Gurl <(E-Mail Removed)> wrote in news:40E066C6.64699ED6
@purlgurl.net:

>> > Brigitte Jellinek:
>> >
>> > http://rec.horus.at/deadlinks/guestbook/formlib.txt


>> Hmmm ... looking at that, I am surprised to see:
>>
>> @k = keys(%in); # I couldn't find a better way of counting
>> $noin = $#k; $noin++; # entries in %in. do YOU know one?
>>
>> I never looked into Perl 4, but I am curious: Would
>>
>> my $k = keys %in;
>>
>> not have worked with Perl 4?


> Why don't you research, read and find out if "my"
> declarations work with Perl 4 installations?
>
>
> Purl Gurl


The 'my' is not the point there. It is just force of habit that I wrote it.
The question is: Would

$k = keys %in;

not have given the number of keys in the hash in Perl4?

--
A. Sinan Unur
(E-Mail Removed) (reverse each component for email address)
 
Reply With Quote
 
Ste (Stefano Russo)
Guest
Posts: n/a
 
      06-28-2004
Thanks a lot guys!!!

Excuseme if i don't quote, but ill'need to quote all the replies..



--
|||
(0.0)
|-------------o00----00o-----------------------------|
|Stefano Alberto Russo - Liceo Oberdan - Trieste |
|www.terra32.net - webmaster @ www.acquariofilia.biz |
|----------------------------------------------------|

 
Reply With Quote
 
Tintin
Guest
Posts: n/a
 
      06-29-2004

"Ste (Stefano Russo)" <(E-Mail Removed)> wrote in message
news:EZYDc.390155$(E-Mail Removed)...
> Hi, i would like to know if is possible to recall a variable passed via
> get trought a url.
>
> example:
>
> www.terra32.net/perl/ping.pl?url=www.google.it
>
> How can i recall the variable "url" in the script?


#!/usr/bin/perl
use strict;
use CGI;

my $q = new CGI;
my $url = $q->param('url');


 
Reply With Quote
 
John Bokma
Guest
Posts: n/a
 
      06-29-2004


Tintin wrote:

> "Ste (Stefano Russo)" <(E-Mail Removed)> wrote in message
> news:EZYDc.390155$(E-Mail Removed)...
>
>>Hi, i would like to know if is possible to recall a variable passed via
>>get trought a url.
>>
>>example:
>>
>>www.terra32.net/perl/ping.pl?url=www.google.it
>>
>>How can i recall the variable "url" in the script?

>
>
> #!/usr/bin/perl


add -T

> use strict;


use warnings;

> use CGI;
>
> my $q = new CGI;


I recommend calling it $cgi instead of $q. It is more than just the
"query", also $cgi is more self-documenting

> my $url = $q->param('url');


Be aware that $url can contain anything and can even be undefined.
Check, check, and reject if it is not what you expect. Don't fix it,
reject it.

--
John MexIT: http://johnbokma.com/mexit/
personal page: http://johnbokma.com/
Experienced Perl programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
-Re: Re: Serious cache problem - Page_Load get never get called !!! Ryan Park ASP .Net 0 01-04-2005 06:09 PM
Serious cache problem - Page_Load get never get called !!! Ryan Park ASP .Net 2 01-03-2005 05:52 PM
Re: use anonymous but get get an authentication box Curt_C [MVP] ASP .Net 2 09-21-2004 06:39 PM
use anonymous but get get an authentication box =?Utf-8?B?U2hhcmlm?= ASP .Net 0 09-21-2004 01:01 PM



Advertisments