naveenkabra has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I would like to know is there any library/standard function available in perl to check whether passed string(as parameter) is URLencoded or not. Thanks, naveen

Replies are listed 'Best First'.
Re: Help on URlencoding
by CountZero (Bishop) on Jun 21, 2006 at 06:00 UTC
    Have a look at CGI::Enurl and CGI::Deurl or URI::Escape.

    For example:

    use strict; use URI::Escape; while (my $string = <DATA>) { chomp $string; if ($string eq uri_unescape($string)) { print "'$string' was not URI-encoded.\n"; } else { print "'$string' was URI-encoded.\n"; } } __DATA__ A%20horse%2C%20a%20horse!%20My%20kingdom%20for%20a%20horse! A plain string

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Re: Help on URlencoding
by GrandFather (Saint) on Jun 21, 2006 at 06:06 UTC

    Do you want to check for URLencoding, or that the string is a valid URL (or URI)?

    Data::Validate::URI can be used to validate URIs of various sorts.


    DWIM is Perl's answer to Gödel
      Hi, how can i download this Data::Validate::URI module and where i need too put it.

        Either use CPAN if you are on a *nix system, or ppm if you use Windows and have ActiveState Perl installed. See the Tutorials section Installing Modules.


        DWIM is Perl's answer to Gödel
Re: Help on URlencoding
by pbeckingham (Parson) on Jun 21, 2006 at 13:04 UTC

    If you actually perform the un-encoding, then if the result differs from the input, then yes, it was encoded.



    pbeckingham - typist, perishable vertebrate.