--- Connie Chan <[EMAIL PROTECTED]> wrote:
> Since we know this :  $string =~ s/([a-fA-F0-9][a-fA-F0-9])/pack ("C", hex($1))/eg;
> 
> is a statement which can converting back the "real string" from
> a form field, but, could anybody tell how to convert the "real string"
> to the "long long" string ??
> 
> Besides, anybody can tell what is the exactly meaning of : ("C", hex($1)) ?

Connie,

Here's the scoop:

    pack ("C", hex($1))

Working from the inside, out, 'hex' is a function that takes hex input and returns the 
integer
value:

    $ perl -e 'print hex "f"'
    15

The $1 has the hex data captured from the regular expression.  From 'perldoc -f pack', 
we see that
if the first argument to pack is an upper case C, it will convert the second argument 
to an
unsigned character (ASCII).

    $ perl -e '@a=qw/4f 76 69 64/;print pack("C",hex$_)for @a'
    Ovid

To get from an ASCII character back to the hex encoded version, use URI::Escape.

    C:\WINDOWS>perl -MURI::Escape -e "print uri_escape(q|Ovid|)"
    Ovid

You might wonder why that printed "Ovid" instead of a bunch of funky hex characters.  
In URIs,
only certain characters need to be escaped.  Ampersands, semi-colons, spaces, and a 
few other
items need escaping.  See 'perldoc URI::Escape' for more information.

    C:\WINDOWS>perl -MURI::Escape -e "print uri_escape(q|& ;+|)"
    %26%20%3B%2B

For a full list of what characters are escaped in URIs, see
http://www.easystreet.com/~ovid/cgi_course/appendices/appendix2.html.  There's also a 
Perl program
at the bottom of the page which shows the use of the URI::Escape module in much 
greater detail.

Cheers,
Curtis "Ovid" Poe

=====
"Ovid" on http://www.perlmonks.org/
Someone asked me how to count to 10 in Perl:
push@A,$_ for reverse q.e...q.n.;for(@A){$_=unpack(q|c|,$_);@a=split//;
shift@a;shift@a if $a[$[]eq$[;$_=join q||,@a};print $_,$/for reverse @A

__________________________________________________
Do You Yahoo!?
Check out Yahoo! Shopping and Yahoo! Auctions for all of
your unique holiday gifts! Buy at http://shopping.yahoo.com
or bid at http://auctions.yahoo.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to