perl: July 2008 Archives

Imagine the scenario: you have a hash of arguments you want to send as a CGI query string to somewhere on the web. Or you might, for instance, need to create an unsubscribe URL to include in your newsletter emails so that people can click a link to stop getting your newsletter.

Here's a one line solution:

my %args = (
             id     => 102546,
             key    => 'kljdlasjd3289290mkdlmca',
             list   => 12,
             action => 'unsubcribe', 
           );
		
my $query_string = join '&', map { "$_=$args{$_}" } keys %args;
my $url = "http://example.com/newsletter?$query_string";

That should create your query string out of all the elements of your hash.

About this Archive

This page is a archive of entries in the perl category from July 2008.

perl: April 2008 is the previous archive.

perl: August 2008 is the next archive.

Find recent content on the main index or look in the archives to find all content.

Powered by Movable Type 4.21-en