|
NAMECGI::Enurl.pm - module for URL-encoding strings and hashesversion 1.07 SYNOPSISuse CGI::Enurl; %hash = (name=>'Jenda Krynicky',address=>'Nerudova 1016'); print "Location: http://$ENV{SERVER_NAME}/cgi-bin/do.pl?",enurl \%hash,"\n\n"; DESCRIPTIONThis is a little module made for CGI scripting. It encodes the parameters to be passed to a CGI. It does nothing more, so it's much smaller and loads more quickly.Functions
EXAMPLE:use CGI::Enurl; print "Location: http://www.somewhere.com/Scripts/search.pl?", enurl('something strange'),"\n\n"; or use CGI::Enurl; print "Location: http://www.somewhere.com/Scripts/search.pl?", enurl('something strange','and other',666),"\n\n"; or use CGI::Enurl; print "Location: http://www.somewhere.com/Scripts/myscript.pl?", enurl({fname => 'Jan',lname => 'Krynický',tel => '+420-2-9618 1234'},1),"\n\n"; or use CGI::Enurl; print "Location: http://www.somewhere.com/Scripts/myscript.pl?", enURL('fname=Jan&lname=Krynický&tel=+420-2-9618 1234&1',"\n\n"; or using the tricks of Interpolation.pm - http://www.plover.com/~mjd/perl/Interpolation/manual.html use CGI::Enurl; use Interpolation URL => \&enurl; print "name=$URL{'Jann Linder, jr'}&address=$URL{'129 kjhlkjd st'}"; or even use CGI::Enurl; use Interpolation enurl => sub {my %hash=split /$;/o,$_[0];enurl \%hash}; # use other name instead of enurl if you like. print "script.pl?$enurl{name=>'Jenda Krynicky',address=>'Nerudova 1016'}\n"; %hash = (name=>'Jenda Krynicky',address=>'Nerudova 1016'); sub var { if (ref $_[0] eq 'HASH') { join $;, %{shift()}, @_; } else { join $;, @_; } } print "script.pl?$enurl{var %hash}\n"; # the "var" is necessary ! # without it you will get : "Odd number of elements in hash list at ... line 2." print "script.pl?$enurl{var %hash,age=>22}\n"; # you may omit the "var" only if you enter the hash as a constant directly # into $enurl{...}. If you want to be cheeky you may use '$?{}' as the interpolator: use CGI::Enurl; use Interpolation '?' => sub {my %hash=split /$;/o,$_[0]; '?' . enurl \%hash}; print "cript.pl$?{a=>5,b=>7,n=>'Jenda Krynicky'}\n"; or use CGI::Enurl; use Interpolation '?' => sub {'?' . enURL $_[0]}; print "cript.pl$?{'a=5&b=7&n=Jenda Krynicky'}\n"; # # or # print qq{cript.pl$?{"a=5&b=7&n=$name"}\n}; Please read the docs for enurl versus enURL so that you understand the difference! DISCLAIMERThe enurl_str function is taken from CGI.pm. (It's named 'escape' there.) Thanks.AUTHORJan Krynicky <Jenda@Krynicky.cz>COPYRIGHTCopyright (c) 1997-2001 Jan Krynicky <Jenda@Krynicky.cz>. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.POD ERRORSHey! The above document had some coding errors, which are explained below:
Visit the GSP FreeBSD Man Page Interface. |