in reply to Re: passing a variable from a link
in thread passing a variable from a link

A slight correction: the above code is going to print animal=pet. If you want to not use CGI.pm (bad, evil, you've been warned, etc.), then $pet is going to contain:
variable1=value1&variable2=value2...
Some fairly rudimentary parsing can get you what you need. However, then you might need to worry about how HTML encodes special characters (what if the user enters "<lephant" or something else silly?) which isn't too bad but you're quickly seeing why CGI.pm is probably a better choice.
Cheers,
Ardenstone

Update:
Here is some ugly not use strict-able code (it creates variables on the fly) that can parse out the environment string:

$myTmp = $ENV{'QUERY_STRING'}; @words = split '&',$myTmp; my $counter = 0; while ($words[$counter]) { my @tmpWords = split '=',$words[$counter]; $tmpWords[1] =~ tr/+/ /; $tmpWords[1] =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; my $tmpName = $tmpWords[0]; $$tmpName = $tmpWords[1]; $counter++; }
Now that's ugly. But it should work.

Replies are listed 'Best First'.
Re: Re: Re: passing a variable from a link
by Flame (Deacon) on Nov 17, 2001 at 21:16 UTC
    Umm, did you notice that I had changed the way the link was used?

    It said "http://whatever.com/cgi-bin/variable.pl?dog"

    So the query string would be "dog" not "animal=dog"

    And, as I said, that method only really works when you are using just one variable.


    -----BEGIN GEEK CODE BLOCK-----
    Version: 3.12
    GIT d- s:++ a--- C++++ UL P+++>++++ L+ E- W++>+++ N !o K- w+ O---- M-- V--
    PS PE Y- PGP t++(+++) 5(+++)++++ X R+@ tv+ b+++ DI+ D- G e->+++ h! r-- y-
    ------END GEEK CODE BLOCK------
    Translate

    "Weird things happen, get used to it."

    Flame ~ Lead Programmer: GMS