Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

common replacement code ill-understood

by Anonymous Monk
on Jun 11, 2006 at 05:33 UTC ( [id://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;

Replies are listed 'Best First'.
Re: common replacement code ill-understood
by davido (Cardinal) 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 (Chancellor) 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
Domain Nodelet?
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?Last hourOther CB clients
Other Users?
Others about the Monastery: (7)
As of 2024-03-28 11:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found