Polymathic has asked for the wisdom of the Perl Monks concerning the following question:
I'm using Windows Subsystem for Linux Perl and I'm getting weird results when printing an array
while (scalar @list_words) { test_if_letters_are_included(); foreach(@list_words) { print "$_\n"; } my @array = qw(this that the other thing); say "@array"; say "@list_words"; say scalar @list_words; }
I truncated the output for brevity. Prints:
...ZONDA ZONED ZONES ZOOID ZOOKS ZOOMS ZOONS ZORIS ZOSMA ZUDDA ZULUS ZUNIS this that the other thing ZUNIS 8471
Any guesses as why I would only get the last element of the @list_words array?
Even weirder yet. If I change "say" to "print" on the @array I get an output that is a mix of both arrays!
while (scalar @list_words) { test_if_letters_are_included(); foreach(@list_words) { print "$_\n"; } my @array = qw(this that the other thing); print "@array"; say "@list_words"; say scalar @list_words; }
Again, I truncated the output for brevity. Prints:
...ZONDA ZONED ZONES ZOOID ZOOKS ZOOMS ZOONS ZORIS ZOSMA ZUDDA ZULUS ZUNIS this that the other thing ZUNIShat the other thingABASE 8471
"ABASE" is the index 14 of @list_words.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Bizarre Perl behavior?
by Corion (Patriarch) on Jan 30, 2022 at 20:04 UTC | |
by Polymathic (Novice) on Jan 30, 2022 at 20:32 UTC | |
by LanX (Saint) on Jan 30, 2022 at 20:56 UTC | |
by Polymathic (Novice) on Jan 30, 2022 at 21:20 UTC | |
by LanX (Saint) on Jan 30, 2022 at 22:52 UTC | |
by Polymathic (Novice) on Jan 30, 2022 at 21:26 UTC | |
by Polymathic (Novice) on Jan 30, 2022 at 21:01 UTC | |
|
Re: Bizarre Perl behavior?
by LanX (Saint) on Jan 30, 2022 at 20:24 UTC | |
by Polymathic (Novice) on Jan 30, 2022 at 20:54 UTC | |
by eyepopslikeamosquito (Archbishop) on Jan 31, 2022 at 07:15 UTC | |
by jwkrahn (Abbot) on Jan 31, 2022 at 04:05 UTC |