Well, you could use a regex to URL encode all the
elements in your URL parameters, then join them together into
a single query string.
But, there is a much simpler way, using the CPAN module
URI.
Below is an example program using URI that does
something similar to what you want:
#!/usr/bin/perl -w
use strict;
use URI;
use constant BASE_URL => 'index.pl';
use constant REFERER => 'http://search.cpan.org/search?dist=URI';
my $uri = URI->new(BASE_URL);
$uri->query_form(
location => 'Redirect',
URL => REFERER,
referer => 'Links',
);
print $uri;
A well formed URL will be printed out, and any parameters
will be URL encoded properly.
A nice bonus is that the code made with URI is easy
to read and hides all the potentially messy URL construction/encoding
details from you. I almost never work with URL's by hand
any longer since I started to use this module.
|