get variables?

Discussion in 'Perl Misc' started by Ste (Stefano Russo), Jun 28, 2004.

  1. 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 |
    |----------------------------------------------------|
     
    Ste (Stefano Russo), Jun 28, 2004
    #1
    1. Advertising

  2. Ste (Stefano Russo)

    Paul Lalli Guest

    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
     
    Paul Lalli, Jun 28, 2004
    #2
    1. Advertising

  3. Purl Gurl <> 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
    (reverse each component for email address)
     
    A. Sinan Unur, Jun 28, 2004
    #3
  4. Purl Gurl <> wrote in
    news::

    > 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 <> 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
    (reverse each component for email address)
     
    A. Sinan Unur, Jun 28, 2004
    #4
  5. 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 |
    |----------------------------------------------------|
     
    Ste (Stefano Russo), Jun 28, 2004
    #5
  6. Ste (Stefano Russo)

    Tintin Guest

    "Ste (Stefano Russo)" <> wrote in message
    news:EZYDc.390155$...
    > 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');
     
    Tintin, Jun 29, 2004
    #6
  7. Ste (Stefano Russo)

    John Bokma Guest

    Tintin wrote:

    > "Ste (Stefano Russo)" <> wrote in message
    > news:EZYDc.390155$...
    >
    >>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
     
    John Bokma, Jun 29, 2004
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. avnrao
    Replies:
    0
    Views:
    3,398
    avnrao
    May 7, 2004
  2. Replies:
    1
    Views:
    967
  3. dwok
    Replies:
    7
    Views:
    732
    Hal Rosser
    Mar 4, 2005
  4. Replies:
    10
    Views:
    36,025
    jporter892
    Jun 6, 2011
  5. Replies:
    9
    Views:
    1,015
Loading...

Share This Page