I liked the output of this function, so I used it for debugging purposes for a while... but in the end I wrote my own simplified variant with some other ideas from here and there which produces exactly the same output:
sub hexdump($)
{
my $offset = 0;
foreach my $chunk (unpack "(a16)*", $_[0])
{
my $hex = unpack "H*", $chunk; # hexadecimal magic
$chunk =~ tr/ -~/./c; # replace unprintables
$hex =~ s/(.{1,8})/$1 /gs; # insert spaces
printf "0x%08x (%05u) %-*s %s\n",
$offset, $offset, 36, $hex, $chunk;
$offset += 16;
}
}
|