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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.