Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Bizarre Perl behavior?

by Corion (Patriarch)
on Jan 30, 2022 at 20:04 UTC ( [id://11140971]=note: print w/replies, xml ) Need Help??


in reply to Bizarre Perl behavior?

Most likely, the content of @list_words is not what you think it is. Maybe it contains terminal control codes, or one single large line.

Note that you output @list_words twice, with no delimiter in between, which will make debugging this much harder.

My first attempt at debugging this would be to add some non-whitespace characters around the elements of @list_words while printing them, and cut down @list_words to say 10 elements that you can also share here:

splice @list_words, 10; # inspect only the first 10 elements use Data::Dumper; local $Data::Dumper::Useqq = 1; # output strings with whitespace chara +cters escaped while (scalar @list_words) { test_if_letters_are_included(); foreach(@list_words) { print "list_words:<$_>\n"; print Dumper $_; # also show the string with whitespace escaped } my @array = qw(this that the other thing); print "@array"; #say "@list_words"; say scalar @list_words; }

Replies are listed 'Best First'.
Re^2: Bizarre Perl behavior?
by Polymathic (Novice) on Jan 30, 2022 at 20:32 UTC

    Thanks for the quick reply. I'll give it a try.

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

      > 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

        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!

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

        Okay, Thanks!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2024-04-18 09:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found