The string comparison operator eq puts its operands into scalar context:
say 'equal' if context('1') eq context('2');
my $c = (defined wantarray) ?
(wantarray ? 'list' : 'scalar')
say '(', shift, '): is in ', $c, ' context';
15:56 >perl 457_SoPW.pl
(1): is in scalar context
(2): is in scalar context
So, neither code snippet is doing what you want. The first compares the sizes of the two arrays. The second compares the size of @array with the value returned by reverse, which
In scalar context, concatenates the elements of LIST and returns a string value with all characters in the opposite order.
To compare the contents of the two arrays, use the smart match operator ~~. See How do I test whether two arrays or hashes are equal?
Hope that helps,
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
Outside of code tags, you may need to use entities for some characters:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||