Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I am programming an AIVDM parser in Perl.
It receives data using UDP (recv), the mechanism seems to work fine.
But the issue is that there are some unknown characters in the message which perl puts into the scalar variable which i cannot seem to get rid of.
I have tried to chomp the scalar which removes the text completely, but length() still reports correctly.
A regex which deletes all hex values which are not numbers or letters, with no effect.
Converted the scalar to hex and back into a another scalar, the new scalar has the same issue.

Code:
while ($sock->recv($msg, 1024)) { $length = length($msg); print "MESSAGE: $msg LENGTH: $length\n"; }
Output is:
MESSAGE: !A LENGTH: 2 MESSAGE: IVDM,1,1,,A,?3nGtL0uPi7pD00,2*46 LENGTH: 34
The first line is ok!
Did you see the second line, where does the space come from?
There is also no newline character in the $msg.

Code:
while ($sock->recv($msg, 1024)) { $length = length($msg); print "MESSAGE: $msg LENGTH: $length"; }
Now without the \n i get this:
MESSAGE: !AI LENGTH: 3MESSAGE: ADM,1,1,,A,13mK@M0P000gVvvTC=4:LgwV2L0B +,0*4C LENGTH: 46MESSAGE: !AIVDM,1,1,,A,40 LENGTH: 16MESSAGE: 2M43AudTF;o0fr +sPTBHl700L0h,0*5A
Now the second message i receive make a new line without me specifieng a \n.

I have been trying to remove these weird characters for days without avail, so i need some help from the experts :)
Update:
while ($sock->recv($msg, 1024)) { $msg1 = substr $msg, 0, -1; print "MESSAGE: $msg1 LENGTH: $length"; }
Does also not give any output at all!

In reply to Unknown characters by HyperDevil

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-04-24 22:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found