Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Problems with converting raw data to text

by bv (Friar)
on Dec 06, 2009 at 15:02 UTC ( #811341=note: print w/replies, xml ) Need Help??


in reply to Problems with converting raw data to text

Have you tried just using the data as-is? $payload looks to me to be a string already, even though it contains non-printable hex chars. It should still be able to match against regular expressions. To print the packet out, you could do something like this:

$payload =~ s/[^[:print:]]/./g;

As a side note, don't quote variables unnecessarily. There is very little difference between "$payload" and $payload, and it's not the difference a shell programmer would expect.


@_=qw; Just another Perl hacker,; ;$_=q=print "@_"= and eval;

Replies are listed 'Best First'.
Re^2: Problems with converting raw data to text
by anderam (Initiate) on Dec 08, 2009 at 12:31 UTC

    Many thanks for your solution of my problem. It Works!

    But I don't understand the magic used in that line. Could you please explain that for me?

    $payload =~ s/[^[:print:]]/./g;

      The [:print:] is a character class matching printable characters. See Character Classes and other Special Escapes for more about character classes. So the statement replaces all non-printable characters with periods.


      @_=qw; Just another Perl hacker,; ;$_=q=print "@_"= and eval;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://811341]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2019-12-09 18:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?