Update: In deference to Arien's concerns.

if ( do{ local$"=''; @array1 == @array2 and "@array1" eq "@array2"} ) +{ print 'They are the same', $/; }

Which of course will also break if you have two arrays,

my @a = ( 'onetwo','', 'three'); my @b = ( 'one', 'two', 'three' );

And as with any shortcuts, you need to know your data before you apply them. If your not comforable with that, don't use it.

Update more:

I'll spell it out for those unable or unwilling to make the mental leap for themselves.

If your data is wholey numeric, then use $"=<any non-numeric-char>.

If your data consists of wholey alpha data use a non-alpha char.

If your data consists of mixed alpha-numeric then use a non-alpha-numeric.

If your data can contain any char in the range 32-127, cosider using a control character (eg."\cA").

If your data can contain any 7-bit char, use an 8-bit char. 128-255.

If there is simply no character that your data does not contain, then you need to compare element-by-element. These cases are very rare. In almost all normal sets of data it is possible to find a single char that you can get away with using, and eq testing of the stringyfied arrays is a simple, and efficient way of performing this kind of test on small datasets.


In reply to Re: Comparing arrays by BrowserUk
in thread Comparing arrays by hotshot

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.