Just figured I'd add another way to do it...
sub quote_eq {
return "@a1" eq "@a2";
}
And the results were....
Benchmark: timing 100000 iterations of join, loop, quote...
join: 3 wallclock secs ( 2.30 usr + 0.00 sys = 2.30 CPU) @ 43
+402.78/s (n=100000)
loop: 17 wallclock secs (16.03 usr + 0.00 sys = 16.03 CPU) @ 62
+37.52/s (n=100000)
quote: 5 wallclock secs ( 3.79 usr + 0.00 sys = 3.79 CPU) @ 26
+420.08/s (n=100000)
join remains in the lead...
Update: Of course this has the same bug that
lhoward pointed out. Assuming lists of single character elements though... :)
Update 2: Alright, so not the same bug, but a similar bug - as
btrott points out... i.e.
my @a1 = ( "3 5 7", "9 11 13" );
my @a2 = qw( 3 5 7 9 11 13 );
result in the same string.
So this algorithm can be used to compare arrays where the elements don't have whitespace... any array created with the qw operator...
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.