Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Why is my code producing weird output?

by hv (Prior)
on Aug 30, 2023 at 23:29 UTC ( [id://11154179]=note: print w/replies, xml ) Need Help??


in reply to Why is my code producing weird output?

I think it is possible that your input file has at some point acquired Windows CR-LF line endings, but you are running it on a Unixish system that expects LF line endings. So the chomp() is stripping the LF but leaving the CR, which then gets included in the joined string that you output.

Without changing the input file, one option to fix that would be to replace the chomp to remove all trailing whitespace:

while (<>) { s{\s+$}{}; ...

It is common that a string with a lone CR ("carriage return") is displayed to the terminal by "returning the carriage" as a typewriter would to the first column without starting a new line (which is what LF, "line feed", does). This could explain the output you are seeing. Piping the output to a hex dump program such as od -x would help to confirm that.

Replies are listed 'Best First'.
Re^2: Why is my code producing weird output?
by BillKSmith (Monsignor) on Sep 01, 2023 at 18:49 UTC
    When you know that you have windows line separators, I prefer to handle them the same way that perl on windows does. Use the "IO Layer" crlf. Add the statement

    binmode STDIN, ':crlf';

    before your input loop.
    Bill
Re^2: Why is my code producing weird output?
by Anonymous Monk on Aug 31, 2023 at 09:41 UTC
    Thank you all! It seems that my input file had some CRs after all! Now it works fine :)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2024-04-17 08:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found