[Omaha.pm] Binary stuff in my logs

Jay Hannah jhannah at omnihotels.com
Wed Sep 27 14:04:34 PDT 2006


A vendor is sending me a few random bytes of binary data in an ASCII
stream. When I'm debugging my logs are hard/impossible to read because
all that crap is in the way.

Here's a little loop to make my logs ugly but readable, and archiving
WHAT binary crap they sent me in a way that I can review it later...

Not bad for a 10m job?  :)

j


$ cat j.pl
my $str = "blah\nand\rstuff\t\t\nline3\cXjunk...";
my $binary_char;
while (($binary_char) = ($str =~ /([^ -~])/)) {
   my $ord = "[ASCII:" . ord($binary_char) . "]";
   $str =~ s/\Q$binary_char\E/$ord/gs;
   print "$str\n";
}
print "$str\n";

$ perl j.pl
stuffASCII:10]an[ASCII:10]line3junk...
blah[ASCII:10]and[ASCII:13]stuff                [ASCII:10]line3junk...
blah[ASCII:10]and[ASCII:13]stuff[ASCII:9][ASCII:9][ASCII:10]line3junk...
blah[ASCII:10]and[ASCII:13]stuff[ASCII:9][ASCII:9][ASCII:10]line3[ASCII:
24]junk...
blah[ASCII:10]and[ASCII:13]stuff[ASCII:9][ASCII:9][ASCII:10]line3[ASCII:
24]junk...




More information about the Omaha-pm mailing list