rnaeye has asked for the wisdom of the Perl Monks concerning the following question:
Hi! Monks,
Why does the first code work, but not the second one? Can you help me understand. Thank you!
#!/usr/bin/perl use warnings; use strict; use 5.010; my @array = qw(x a m a x); my @reversed = reverse @array; if (@array eq @reversed){ say "this's a palindrome."; } else { say "this's not a palindrome"; }
#!/usr/bin/perl use warnings; use strict; use 5.010; my @array = qw(x a m a x); if (@array eq (reverse @array)){ say "this's a palindrome."; } else { say "this's not a palindrome."; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Palindrome array
by LanX (Saint) on Dec 29, 2012 at 06:13 UTC | |
Re: Palindrome array
by Athanasius (Archbishop) on Dec 29, 2012 at 06:04 UTC | |
Re: Palindrome array
by davido (Cardinal) on Dec 29, 2012 at 09:47 UTC | |
Re: Palindrome array
by Jim (Curate) on Dec 29, 2012 at 09:01 UTC | |
Re: Palindrome array
by karlgoethebier (Abbot) on Dec 29, 2012 at 19:35 UTC | |
Re: Palindrome array
by 2teez (Vicar) on Dec 29, 2012 at 05:52 UTC | |
by LanX (Saint) on Dec 29, 2012 at 17:47 UTC | |
by 2teez (Vicar) on Dec 29, 2012 at 18:33 UTC | |
by AnomalousMonk (Archbishop) on Dec 29, 2012 at 20:18 UTC |
Back to
Seekers of Perl Wisdom