how do I retranslate escaped characters 
Author Message
 how do I retranslate escaped characters

Hi !

http (the transfer protocol of WWW) escapes difficult characters like
this:   '%', followed by the character code in hex
e.g.  +   is encoded as %2B  .

Now I've got a string $val containing zero or more such escaped characters.  
How do I translate them back ?

I've tried

      while($val=~/%(..)/)
          {
          $h=$1;
          $c = pack('c', hex($h));
          $val =~ s/%$h/$c/g;
          };

but surely there must be a better way to do it ?   (A friend told
me he saw a oneline for doing it - but he can't remember where..)

   thanx in advance

     Brigitte

--
Brigitte Jellinek     | WWW: " http://www.*-*-*.com/ ;

Salzburg University   |            Help!  I'm caught in the Web.



Mon, 06 May 1996 00:08:59 GMT  
 how do I retranslate escaped characters

|http (the transfer protocol of WWW) escapes difficult characters like
|this:   '%', followed by the character code in hex
|e.g.  +   is encoded as %2B  .
|
|Now I've got a string $val containing zero or more such escaped characters.  
|How do I translate them back ?
|
|I've tried [...] but surely there must be a better way to do it ?

This is shorter. I don't know about better:

$_="%4a%75%73%74%20%61%6e%6f%74%68%65%72%20%70%65%72%6c%20%68%61%63%6b%65%72";

s/%(..)/pack('c',hex($1))/ge;

print $_,"\n";

#Tim



Mon, 06 May 1996 01:50:59 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Formats: Escaping Characters

2. CGI hangs due to dodgy escape character

3. problems with the \n escape character

4. Escaping cursor characters

5. Variables and escaped characters in RegExp

6. regex to escape special characters

7. Striping VT100 escape characters from a file

8. Why do escape characters show when printing?

9. Which characters need escaping list?

10. Automatically escape characters?

11. How to convert literal escape to ascii character?

12. backtick operator and escape characters...

 

 
Powered by phpBB® Forum Software