#!/usr/bin/perl -w #Prints out an ascii map of a file. use strict; my ($length) = 15; if ($ARGV[0]) { open (FILE, "$ARGV[0]") || die ("Can't open the file you specified!\n"); my ($count) = 0; my ($bytes); my ($buffer) = ""; my (%uniques); while ( read (FILE, $bytes, $length) ) { if ($count % $length == 0) { print ("-------------- ROW: $count --- [$bytes]\n"); } my (@string) = split(//, $bytes); foreach my $e (@string) { #Assign this to the unique hash. $uniques{$e} = ""; #Print out some warnings regarding invisible chars. my ($info) = ""; my ($asciival) = ord $e; ($info, $e) = tweak($e); print "$count:\t$e\t-> ", $asciival, " $info\r\n"; $count++; } } print ("--------------\nTOTAL BYTES: $count \tUNIQUE CHARS: ", scalar keys %uniques, "\n\n"); close (FILE); } else { die ("Usage: asciimap.pl filename\n"); } sub tweak { my ($byte) = @_; my ($bytecopy) = $byte; my (%invisibles) = ( chr(8) => "(Backspace)", chr(9) => "(Horizontal tab)", chr(10) => "(Newline)", chr(11) => "(Vertical tab)", chr(13) => "(Carriage return)" ); my (@arr) = keys %invisibles; foreach my $elem (@arr) { if ("$byte" eq "$elem") { return ($invisibles{$elem}, ""); } } return ("", "$bytecopy"); }