Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env perl
- #-----------------------------------------------------------------------
- # Created: 2017-11-21
- # $Id: hexify,v 1.2 2017/11/22 06:29:35 root Exp root $
- #-----------------------------------------------------------------------
- # FIXME - special cases:
- # - Single \x0a is valid utf8, but should be cucked
- #-----------------------------------------------------------------------
- while (<>) {
- chomp;
- # If it looks like utf8, print it.
- if (eval "\$test = decode( 'utf8', \$_, Encode::FB_CROAK )") {
- print $_;
- } else {
- # If it isn't in the 7-bit ASCII printable range, HEX it.
- if ( /[^\x20-\x39\x3b-\x7e]/ ) {
- print '$HEX[' . unpack("H*", $_) . ']';
- } else {
- print $_;
- }
- }
- print "\n";
- }
- #-----------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement