in reply to Help with raw data.

Unfortunitally unpack and ord are not the answer. :( So I am trying to use regular expressions to match the ÂU or something like it. The problems is that it I don't know how perl sees it and looking for this \302U^K doesn't seem to work as well. Maybe my regular expressions suck. This is what I have tried:
( $line =~ m/'*(?!a-zA-Z0-9)'/) ( $line =~ m/'\\[0-9]*'/)
Neither one worked. Maybe I am doing something wrong. Any help is greatly appreciated.

Thanks,
Sam Gold

Replies are listed 'Best First'.
Re: Re: Help with raw data.
by graff (Chancellor) on Oct 25, 2003 at 23:43 UTC
    Unfortunitally unpack and ord are not the answer.

    Um... what was the question? Based on the original post, I thought it was:

    How can I convert that from raw to hex or raw to decimal?

    So now the next question is: if you think unpack and ord are not the answer, why not? What did you try, what did you hope to get, and what did you actually get instead? Show us some code.

    Based on the original question, I would think something like this would do:

    # assume $sql contains an sql statement read from a file; # we want to print the statement, showing visible ascii # characters as-is, and converting other things to hex: @bytes = split //, $sql; for ( @bytes ) { if ( /[\x21-\x7e]/ ) { print " $_"; } else { printf( " %0.2x", ord ); } }
    YMMV, depending on what OS and Perl version you're using... e.g. Redhat 8 (9?) combined with Perl 5.8.0 might need some special pragmas to do this right (use bytes; no utf8; maybe binmode ":raw" on the file handle(s) involved).

    Note that the above will show things like " 20 " for spaces, " 0a " for line-feeds, etc; just add stuff into the character class for "printable ascii" characters if you want whitespace printed out as-as.