# This is a simple script that dumps a hexadecimal # representation of a file # It was origginally written in C, so it suffers from some # C syntax (mostly `for' loops could probably be redone # in a more `perlish' way and the use of ternary operator # ?: is quite ugly). It also overuses printf's where a more # elegant solution with `unpack' could be found. # Never-the-less, it did the job that I needed to do, so # here it is for all to see (and maybe even use). use strict; use warnings; $#ARGV == 0 or die 'Usage: hexdump.pl file'; open my $inpt, "<$ARGV[0]" or die "Can't open $ARGV[0]"; binmode $inpt; # for DOS and the rest... for(my $line_no = 0; my $i = read $inpt, $_, 16; $line_no++) { push my @a, split //; # put things onto char array printf "%05x ", $line_no; # print line number # print hex codes printf "%02x ", ord() & 0xff foreach @a; # pad last line if neccessary for(my $j = $#a; $j < 15; $j++) { print ' '; } # if a character is a control character, print a dot, # else print normal ascii char (ord() < 32 or ord() == 127) ? print "." : print foreach @a; print "\n"; } close $inpt;