- dumps ascii values of all characters matching \W - reads from file or stdin).. - useful for analyzing unkown binary file formats.. - files must fit into ram
#!/usr/bin/perl $filename = $ARGV[0] || '/dev/stdin'; $/=undef; open(FILE,$filename) or die $!; $file=<FILE>; close(FILE); $file=~s/(\W)/&replace($1)/eg; print $file; sub replace { return "(".ord($_[0]).")" }

Replies are listed 'Best First'.
(jeffa) Re: showascii
by jeffa (Bishop) on Jul 20, 2003 at 13:56 UTC

    If you are going to slurp an entire filehandle into memory, then do it like this:

    my $text = do {local $/;<FILE>};
    More consise, but also safer in that the undefining of $/ has been tucked away in a 'temporary' scope. But there is no reason to slurp the entire file into memory - you could have just as easily used a while loop to read one line at a time. In fact:
    perl -pe 's/(\W)/"(".ord($1).")"/eg' foo.bin
    works just as well and is more justified for not using strict. ;)

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)