Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Strings mangled on printing

by Paladin (Vicar)
on Jun 03, 2015 at 17:40 UTC ( #1128976=note: print w/replies, xml ) Need Help??


in reply to Strings mangled on printing

Check to see if $rt has a carriage return character at the end of it. Perhaps add something like $rt =~ s/\r//g; to strip any out.

Replies are listed 'Best First'.
Re^2: Strings mangled on printing
by atcroft (Abbot) on Jun 03, 2015 at 18:12 UTC

    $rt = $inp; chomp $rt; # insert at line 23 $rt =~ s/Remote Temp://;

    chomp() would probably be more appropriate, since it removes (from the docs) "any trailing string that corresponds to the current value of $/ (also known as $INPUT_RECORD_SEPARATOR in the 'English' module)", and $/ can be set to the appropriate value if there is a difference in line endings/separators (such as "\n" vs. "\r" vs "\r\n" vs. ...).

    Hope that helps.

      atcroft:

      Normally, I'd agree with you, but since the data is coming over a serial port, I wouldn't expect the line endings to be consistent with those used on whatever platform runs the code. So in this case, I'd prefer explicit removal of junk from the end.

      ...roboticus

      When your only tool is a hammer, all problems look like your thumb.

Re^2: Strings mangled on printing
by gordu (Initiate) on Jun 03, 2015 at 17:51 UTC

    Arrgh!!!! So simple. I should have asked years ago. Yes that fixed it. Thank you!

      Also note that $inp =~ s/\s+$//; will remove all trailing white space, including newlines (\n) and returns (\r).

      Update: Correct typo (per reply).

        Actually, $inp =~ s/\s$//; will remove only a single whitespace character at the end of the line.

        Use $inp =~ s/\s+$//; to remove all of them.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1128976]
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: (7)
As of 2022-05-20 08:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (73 votes). Check out past polls.

    Notices?