Oh hi, I just thought I'd golf a solution. I'm sure other people can
do a much better job than I making a full hexdumping suite, so I just ad some fun. Can't seem to get it lower than 78 characters,
unfortunately.
i=0;$<.read.scan(/.{0,16}/m){puts"%08x "%i+$&.unpack('H4'*8).join(' );i+=16}
Expanded and parenthesified, clarified:
i = 0
ARGF.read.scan(/.{0,16}/m) {
puts(("%08x " % i) + $&.unpack('H4'*8).join(' '))
i += 16
}
ARGF (aliased as $<) is the file handle of all file names given in the rguments concatenated, STDIN if none exactly what we need. The
regex to scan matches between 0 and 16 characters (including newline) reedily. Change it to 1,16 if you don't want the empty line at the end.
Instead of letting the block to scan take an argument, I used a trick icked up from the last Ruby Quiz I participated in (Obfuscated
Email), and use $& inside the block, which is the last regex match.
Saves two characters \o/
The unpack returns an array of eight strings, each of four characters, ith the hexadecimal representation of the ASCII value of two
consecutive characters. Fun, fun, fun.