"be consistent" | |
PerlMonks |
Print Behavior with Carriage Returnby parapunker81 (Novice) |
on Jan 05, 2020 at 03:37 UTC ( [id://11110962]=perlquestion: print w/replies, xml ) | Need Help?? |
parapunker81 has asked for the wisdom of the Perl Monks concerning the following question:
Greetings, I came across some odd behavior when using the print function and I was curious to see if someone could explain to me why it happened. In my script, I read in a file that contained lines with two strings connected with an equal sign (e.g. string1=string2). As I read in each line, I chomped off the newline character at the end, split on the equal sign, and then created a hash where the key was the second string and the value was the first. I would then loop through the hash like this: I was expecting it to print: The key is value But what I got was: is value After pulling my hair out, I finally realized that the file I was reading in was created in Windows so each line ended with a carriage return. The chomp only removed the \n and left the \r. So each key had a \r at the end of it. Once I removed the \r character it printed out just fine. My question is why did the print function not print anything before the \r character? Thanks!
Back to
Seekers of Perl Wisdom
|
|