Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^3: Bizarre Perl behavior?

by LanX (Saint)
on Jan 30, 2022 at 20:56 UTC ( [id://11140975]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Bizarre Perl behavior?
in thread Bizarre Perl behavior?

> when I run this on my Windows version of Perl it does not have the output problem and prints as expected.

sounds like you are printing control code characters which are messing with the terminal.

Like a CR without LF might overwrite the same line over and over again.

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

Replies are listed 'Best First'.
Re^4: Bizarre Perl behavior?
by Polymathic (Novice) on Jan 30, 2022 at 21:20 UTC
    sounds like you are printing control code characters which are messing with the terminal. Like a CR without LF might overwrite the same line over and over again.

    You guessed it correctly! There was \r\n at the end of every word in the array. I was using chomp and I should have been using something like $_ =~ s/\r[\n]*//; to remove it.

    Thanks for the help!

      > There was \r\n at the end of every word in the array. I was using chomp and I should have been using something like $_ =~ s/\r[\n]*//; to remove it.

      Please note that chomp depends on $/, which is "\n" by default.

      But chomp's understanding of a so called logical "\n" is adjusted to the current OS.

      > > > I'm using Windows Subsystem for Linux Perl ..

      So because you were running the same data thru different OS, the "\r" wasn't always caught.

      Hence setting local $/ = "\x0D\x0A"; before chomping should solve your issue too.°

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

      °) updated explicit "\x0D\x0A" because this logical "\n" is too confusing

Re^4: Bizarre Perl behavior?
by Polymathic (Novice) on Jan 30, 2022 at 21:26 UTC

    Thanks! You were right. It was \r\n and the end of every word in the array

Re^4: Bizarre Perl behavior?
by Polymathic (Novice) on Jan 30, 2022 at 21:01 UTC

    Okay, Thanks!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2024-04-20 01:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found