in reply to Identical Arrays
Oh, don't use either a or b for user Perl variables. In this case, it is ok, but $a and $b are special variables reserved for sort() and other uses. Unlike many other languages, $a is distinct from @a... the same name can be used for different variable types. However, "a" and "b" are so special that I cannot recommend that.#/usr/bin/perl -w use strict; use v5.10.0; my @x = (1, 2, 3); my @y = (2, 3, 1); my @z = (1, 2, 4); print "x and y are equivalent" if sort (@x) ~~ sort (@y); # the sort order (numeric or alpha) doesn't matter # as long as it is consistent. __END__ x and y are equivalent
Update:
I see that I got a "down vote", well ok. Tell us what is wrong about this? I tend to stay away from this "smart match" thing, but it does work and is easy to understand for simple data structures - what it does for more complex structure IS hard to understand. The Perl sort algorithm works just fine for relatively small numbers of items.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Identical Arrays
by Anonymous Monk on Aug 26, 2012 at 05:07 UTC | |
by Marshall (Canon) on Aug 26, 2012 at 05:30 UTC | |
by davido (Cardinal) on Aug 26, 2012 at 06:14 UTC |