The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

CGI::UriThingy - a fewest set of functions about uri thingies.

SYNOPSIS

 use CGI::UriThingy qw(urlencode urldecode);
 
 my %input = (
     'name' => 'Masanori HATA',
     'mail' => 'lovewing@dream.big.or.jp',
     'home' => 'http://go.to/hata',
     );
 my $encoded = urlencode(%input);
 print $encoded;
 
 my %output = urldecode($encoded);
 print 'name: ', $output{'name'}; # displays "name: Masanori HATA"

DESCRIPTION

This module provides four minimal functions about urlencode and uri-escape those which could be needed for CGI program.

FUNCTIONS

urlencode(%param)

Exportable function. With given %param (the names and the values pairs), this function escape, combine and return urlencoded string. A urlencoded string has jointed the names and the value pairs by "&" character, and a name/value pair has jointed the name and the value by "=" character.

Though it is expressed virtually input with a hash (%), it is actually input with an arry (@). So, jointed name/value pairs appear in urlencoded string be in exact sequence of which they have been given. That you can control sequence of name/value pairs appear in urlencoded string. If you just give a real hash (%) to this function, order of name/value pairs appear in urlencoded string should be random.

 $encoded = urlencode(
     name1 => value1,
     name2 => value2,
     (...)
 );
 
 $encoded = "name1=value1&name2=value2&(...)";

Note that the application/x-www-form-urlencoded is specified in HTML 4 http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4.1.

urldecode($string)

Exportable function. This function decode and return names/values pairs from given uri-encoded string. You may input them into a hash (%).

 %param = urldecode($encoded);
uri_escape($string)

Exportable function. This function escape given string. A return value of this function is total number of escaped characters. The uri-escape is specified in RFC 2396 http://www.ietf.org/rfc/rfc2396.txt (and it is partially updated by RFC 2732). The module URI::Escape does a similar function.

uri_unescape($string)

Exportable function. This function unescape given uri-escaped string. A return value of this function is total number of unescaped characters.

SEE ALSO

HTML 4: http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4.1
RFC 2396: http://www.ietf.org/rfc/rfc2396.txt
RFC 2732: http://www.ietf.org/rfc/rfc2732.txt

AUTHOR

Masanori HATA http://go.to/hata (Saitama, JAPAN)

COPYRIGHT

Copyright (c) 1999-2005 Masanori HATA. All rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.