A quick search revealed a few snippets which give hex dumps:
kschwab's version
OeufMayo's version
For fun, I wrote my own version. I said for fun, so the style is unusual and the code could surely be optimized a bit. But it's tested.
use strict; use warnings; use Algorithm::Loops qw( Filter ); my $blank = '.'; # or "\xFA"; open(my $fh, '<', @ARGV ? $ARGV[0] : '-') or die("Unable to open input file: $!\n"); binmode($fh); local $/ = \16; while (my $block = <$fh>) { my ($hex) = map { substr($_.(' 'x51), 0, 51) } join ' ', map /.{1,12}/sg, join ' ', map { sprintf '%02X', $_ } map ord, map /./sg, $block; my ($chr) = Filter { s/[^[:print:]]|\s/$blank/sg } $block; print("$hex $chr\n"); }
Sample run:
>perl hexdump.pl < hexdump.pl 75 73 65 20 73 74 72 69 63 74 3B 0D 0A 75 73 65 use.strict;..use 20 77 61 72 6E 69 6E 67 73 3B 0D 0A 0D 0A 75 73 .warnings;....us 65 20 41 6C 67 6F 72 69 74 68 6D 3A 3A 4C 6F 6F e.Algorithm::Loo . . . 0D 0A 20 20 20 70 72 69 6E 74 28 22 24 68 65 78 .....print("$hex 20 20 20 24 63 68 72 5C 6E 22 29 3B 0D 0A 7D 0D ...$chr\n");..}. 0A .
In reply to Hex Dump
by ikegami
in thread I want to know exactly what comes through a socket
by ivanatora
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |