Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

common replacement code ill-understood

by Anonymous Monk
on Jun 11, 2006 at 05:33 UTC ( #554654=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I see this rather a lot on scripts I download, but I don't really understand it. Can anyone help? Thanks.

$foo =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

Comment on common replacement code ill-understood
Download Code
Re: common replacement code ill-understood
by davido (Archbishop) on Jun 11, 2006 at 05:45 UTC

    It matches a two-digit hexidecimal number preceded by a %. That entity ( %7F, for example) is converted to a base-10 equivalent (some number between 0 and 255), and then that number is converted into a single byte, and substituted into the original string in place of the original hexidecimal entity.

    See perlre, hex, and pack for further information.


    Dave

Re: common replacement code ill-understood
by Joost (Canon) on Jun 11, 2006 at 06:52 UTC

      You can use CGI to decode parameters, but it won't decode the main url part. CGI doesn't have a generic %-unescape routine.

        To escape and unescape URI/URL escape characters, use URI::Escape. A very handy module.


        If the information in this post is inaccurate, or just plain wrong, don't just downvote - please post explaining what's wrong.
        That way everyone learns.

Re: common replacement code ill-understood
by planetscape (Canon) on Jun 11, 2006 at 19:50 UTC
Re: common replacement code ill-understood
by chromatic (Archbishop) on Jun 12, 2006 at 04:40 UTC

    It means that the code probably has bugs, especially security problems.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://554654]
Approved by McDarren
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (5)
As of 2014-12-27 11:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (177 votes), past polls