#!/usr/bin/perl use strict; if (@ARGV < 1) { print STDERR "\nUsage: $0 filename [bytes]\n\n"; exit; } my ($File, $Bytes) = @ARGV; my ($numread, $totread, $lines); my ($ch, $input, $hex, $text); if (!open(IN, $File)) { print STDERR "\nError opening file: $File\n\n"; exit; } while ($numread = read(IN, $input, 16)) { $totread += $numread; $hex = $text = ''; for $ch (unpack("C16", $input)) { $hex .= sprintf("%2.2x ", $ch); if ($ch >= 0x20 && $ch < 0x7f) { $text .= chr($ch); } else { $text .= '.'; } } substr($hex, 24, 0, ' '); printf(STDOUT "%8.8x %-48.48s %-16.16s\n", $lines * 16, $hex, $text); if (++$lines % 8 == 0) { print "\n"; } if ($Bytes && $totread >= $Bytes) { last; } }