in reply to comparison of two arrays

If you want to check for content but not order, and would rather have more speed (for larger numbers of items) at the cost of a bit more memory:
use strict; use warnings; my @array1 = ('anu','abu','ali'); my @array2 = ('anu','abu'); print mycmp(\@array1, \@array2); sub mycmp { my ($a1, $a2) = @_; return 0 if $#$a1 != $#$a2; my %h; $h{$_}++ for @$a1; $h{$_}-- for @$a2; for (values %h) { return 0 if $_; } return 1; }

Replies are listed 'Best First'.
Re^2: comparison of two arrays
by lax (Initiate) on Jun 19, 2006 at 07:00 UTC
    hi

    Thanks a lot for your excellent code
    it really works

    thanks®ards
    lax