EvoTalk

24 六月, 2009

Javascript Like escape and unescape Functions in PERL

Posted by: asd In: Code Snippet| Perl| 程式設計 ()

PERL:
  1. sub escape {
  2. my($str) = splice(@_);
  3. $str =~ s/(\W)/sprintf('%%%02X', ord($1))/eg;
  4. return $str;
  5. }
  6.  
  7. sub unescape {
  8. my($str) = splice(@_);
  9. $str =~ s/%(..)/chr(hex($1))/eg;
  10. return $str;
  11. }

Releated Posts



No Responses to "Javascript Like escape and unescape Functions in PERL"

Comment Form