Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Re: comparing array elements

by Anonymous Monk
on Nov 21, 2003 at 09:44 UTC ( [id://308833]=note: print w/replies, xml ) Need Help??


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

the hash backfired! so i'm using a for loop. (little success so far) my comparison operator isn't working (both arrays contain 4- letter words) and i just need to determine which words are contained in the same position in each array.

thanks for helping!

for (my $i =0; $i < @forward_tets; $i++) { if ($forward_tets[$i] =~ $reverse_tets[$i]) { print "$forward_tets[$i] \t $reverse_tets[$i]\n" +; } }

Replies are listed 'Best First'.
Re: comparing array elements
by Abigail-II (Bishop) on Nov 21, 2003 at 09:51 UTC
    To compare two strings for equality, one uses eq, not =~ (although, if the words just contain letters, it would work too).

    Abigail

      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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://308833]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-04-25 12:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found