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 | |
|
Re^2: Why is my code producing weird output?
by Anonymous Monk on Aug 31, 2023 at 09:41 UTC |