<[EMAIL PROTECTED]> wrote: > Hi > > I would like to know how to compare 2 arrays. > > I have 2 arrays and I would like to compare the contents of the data. > It doesn't matter in which order the data is stored so long as its the same. > So comparing the bellow should read true, but if they didn't match it would > be false. > > my @foo = qw( > foo bar cat dog > ); > my @bar = qw( > dog cat foo bar > );
One way to do it: #!/usr/bin/perl -w use strict; my @foo = qw(this that and something); my @bar = qw(that and something this); my @result; foreach my $fooline (@foo) { foreach my $barline (@bar) { push(@result, $barline) if $barline eq $fooline; } } print "true\n" if scalar(@result) == scalar(@foo); This does however assume text-fields in the arrays. Tor -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]