Skip to content

Instantly share code, notes, and snippets.

@binary132
Created April 22, 2013 18:17
Show Gist options
  • Save binary132/5437239 to your computer and use it in GitHub Desktop.
Save binary132/5437239 to your computer and use it in GitHub Desktop.
Hex dump STDIN to STDOUT, with byte index and ASCII text display.
#!/usr/local/bin/perl
# Bodie Solomon 2013
# question 2: hex dump
use strict;
use warnings;
{
local $/ = \16;
while (<>) {
printf "%08d: %08X %08X %08X %08X %s\n",
10 * ($.-1),
vec($_, 0, 32),
vec($_, 1, 32),
vec($_, 2, 32),
vec($_, 3, 32),
do{ (my $str = $_) =~ s/[^!-~]/\./g; $str };
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment