Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Answer: How do I compare two strings against two arrays respectively?

( #67486=categorized answer: print w/ replies, xml ) Need Help??

Q&A > strings > How do I compare two strings against two arrays respectively? contributed by ariels

Here's another way to do it, if I correctly understand what you want to do. You want to find an index $i for which $a[$i] eq $a and $b[$i] ne $b (that is, your condition holds at the same index). So why are you searching the array elements? It's better to search for an appropriate index!
@indices = grep { $a[$_] eq $a and $b[$_] ne $b } (0..$#a);

Comment on Answer: How do I compare two strings against two arrays respectively?
Download Code
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (9)
As of 2014-08-23 18:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (176 votes), past polls