#!/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 hexed #----------------------------------------------------------------------- use utf8; 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 ( /(\S*)([^\x20-\x39\x3b-\x7e])(\S*)/ ) { print $1 . unpack("H*", $2) . $3; } else { print $_; } } print "\n"; } #-----------------------------------------------------------------------