#!/usr/bin/perl
# print a hex dump of a file -- good for systems that don't have hd
# Good on systems that do since you don't have to remember hd options
# Gerry Patterson, 2002
open(INPF, "< $ARGV[0]") or die "Unable to open file: ARGV[0]";
binmode(INPF);
$FilePtr = 0;
while( $n = sysread INPF,$Buf,1024){
	for ($i = 0; $i < $n; $FilePtr += 16){
		$t = substr( $Buf, $i, 16);	
		@T = unpack "C*",$t;
		$HexStr = sprintf "%04X ", $FilePtr;
		for $j ( 0 .. 15){
			if ( $i++ < $n){
				$HexStr .= sprintf " %02X", $T[$j];
				$T[$j] = 46 if ( $T[$j] < 32 || $T[$j] > 126);
			}
			else{
				$HexStr .= "   ";
				$T[$j] = 32;
			}
			$HexStr .= " " if ($j == 7);
		}
		$AscStr = pack "c*", @T;
		print "$HexStr  $AscStr\n";
	}
}
