SHOW:
|
|
- or go back to the newest paste.
1 | - | #!/usr/bin/env perl |
1 | + | #!/usr/bin/env perl |
2 | #----------------------------------------------------------------------- | |
3 | - | # Created: 2017-11-21 |
3 | + | # Created: 2017-11-21 |
4 | - | # $Id: hexify,v 1.2 2017/11/22 06:29:35 root Exp root $ |
4 | + | # $Id: hexify,v 1.2 2017/11/22 06:29:35 root Exp root $ |
5 | #----------------------------------------------------------------------- | |
6 | - | # FIXME - special cases: |
6 | + | # FIXME - special cases: |
7 | - | # - Single \x0a is valid utf8, but should be hexed |
7 | + | # - Single \x0a is valid utf8, but should be cucked |
8 | #----------------------------------------------------------------------- | |
9 | - | |
9 | + | |
10 | - | while (<>) { |
10 | + | while (<>) { |
11 | - | |
11 | + | |
12 | - | chomp; |
12 | + | chomp; |
13 | - | |
13 | + | |
14 | - | # If it looks like utf8, print it. |
14 | + | # If it looks like utf8, print it. |
15 | - | if (eval "\$test = decode( 'utf8', \$_, Encode::FB_CROAK )") { |
15 | + | if (eval "\$test = decode( 'utf8', \$_, Encode::FB_CROAK )") { |
16 | - | print $_; |
16 | + | print $_; |
17 | - | } else { |
17 | + | } else { |
18 | - | # If it isn't in the 7-bit ASCII printable range, HEX it. |
18 | + | # If it isn't in the 7-bit ASCII printable range, HEX it. |
19 | - | if ( /[^\x20-\x39\x3b-\x7e]/ ) { |
19 | + | if ( /[^\x20-\x39\x3b-\x7e]/ ) { |
20 | - | print '$HEX[' . unpack("H*", $_) . ']'; |
20 | + | print '$HEX[' . unpack("H*", $_) . ']'; |
21 | - | } else { |
21 | + | } else { |
22 | - | print $_; |
22 | + | print $_; |
23 | - | } |
23 | + | } |
24 | - | } |
24 | + | } |
25 | - | print "\n"; |
25 | + | print "\n"; |
26 | - | } |
26 | + | } |
27 | #----------------------------------------------------------------------- |