The ugly truth is both don't work!
eq forces scalar context and is meant to compare strings
So in the first code you are checking if the sizes (after stringification) are equal.
DB<107> @a = 1..3
=> (1, 2, 3)
DB<108> @a eq "3"
=> 1
in the second you have scalar from reverse on RHS
DB<123> (reverse @a)
=> (3, 2, 1)
DB<124> scalar (reverse @a)
=> 321
DB<125> "321" eq (reverse @a)
=> 1
please stop doing weird things!
you can try the (less weird) smart match operator ~~ to compare arrays.
DB<129> @a=(3,1,3)
=> (3, 1, 3)
DB<130> @a ~~ [reverse @a]
=> 1
DB<131> @a ~~ [3,1,3]
=> 1
DB<132> @a=1..3
=> (1, 2, 3)
DB<133> @a ~~ [reverse @a]
=> ""
a poor man's solution with eq is to explicitly stringify on both sides.
DB<143> @a=(3,1,3)
=> (3, 1, 3)
DB<144> @ar=reverse @a
=> (3, 1, 3)
DB<145> "@a"
=> "3 1 3"
DB<146> "@a" eq "@ar"
=> 1
But this depends on the nature of your array elements, don't be too surprised about:
DB<151> "@a"
=> "3 1 3"
DB<152> @b=(3,"1 3")
=> (3, "1 3")
DB<153> "@a" eq "@b"
=> 1
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:
- 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
Outside of code tags, you may need to use entities for some characters:
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.