Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env perl
  2. #-----------------------------------------------------------------------
  3. # Created: 2017-11-21
  4. # $Id: hexify,v 1.2 2017/11/22 06:29:35 root Exp root $
  5. #-----------------------------------------------------------------------
  6. # FIXME - special cases:
  7. # - Single \x0a is valid utf8, but should be cucked
  8. #-----------------------------------------------------------------------
  9.  
  10. while (<>) {
  11.  
  12. chomp;
  13.  
  14. # If it looks like utf8, print it.
  15. if (eval "\$test = decode( 'utf8', \$_, Encode::FB_CROAK )") {
  16. print $_;
  17. } else {
  18. # If it isn't in the 7-bit ASCII printable range, HEX it.
  19. if ( /[^\x20-\x39\x3b-\x7e]/ ) {
  20. print '$HEX[' . unpack("H*", $_) . ']';
  21. } else {
  22. print $_;
  23. }
  24. }
  25. print "\n";
  26. }
  27. #-----------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement