use strict;
use URI::URL;
sub addEnvVar ($$$$)
{
my $URL = shift;
my $name = shift;
my $value = shift;
my $returnRef = shift;
# Create the URL as an object and extract already existing parameters.
my $url = new URI::URL ($URL);
my $qstring = $url->equery ();
# Split the parameters up.
my @params = split (/\&/, $qstring);
# Split the name=value pairs up and place them in a parameter list.
my @paramList;
foreach my $param (@params)
{
my ($pname, $pvalue) = split (/\=/, $param);
push (@paramList, $pname);
push (@paramList, $pvalue);
}
# Add the new parameters to the end of the list.
push (@paramList, $name);
push (@paramList, $value);
# Place the parameter list in the URL.
$url->query_form (@paramList);
# Get the resulting URL after appending the new variable.
my $newURL = $url->as_string ();
$$returnRef = $newURL;
return 1;
}
The only minor problem I had testing this occurred when I tried to have parameters such as:
carr%20ots=cooked
These would appear in the resulting URL as:
carr%2520ots=cooked
But I'm not sure if its even legal to have such things in
parameters. I think I'll stick with this for now.
Thanks a lot for your help,
Leigh
In reply to Re: •Re: Adding param to a specified URL
by Anonymous Monk
in thread Adding param to a specified URL
by maltesehamster
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |