in reply to Re: Re: comparing array elements
in thread comparing array elements

To compare two strings for equality, one uses eq, not =~ (although, if the words just contain letters, it would work too).

Abigail

Replies are listed 'Best First'.
Re: Re: comparing array elements
by Anonymous Monk on Nov 21, 2003 at 10:02 UTC
    yep, but this loop seems to be comparing every position in the first array to every position in the second, not one at a time! How can I do this?

      Why do you need two for-loops? Wouldn't one work?

      my @array1 = ('test', 'text', 'next'); my @array2 = ('text', 'test', 'next'); for (my $i=0; $i < scalar(@array1); $i++) { if ($array1[$i] eq $array2[$i]) { print "$array1[$i] matches\n"; } }
      How's that possible? You index both arrays with the same key.

      Abigail

        ok, you're right.. its not working - it thinks both arrays are the same