Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

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

by ariels (Curate)
on Mar 27, 2001 at 17:43 UTC ( #67486=categorized answer: print w/replies, xml ) Need Help??

Q&A > strings > How do I compare two strings against two arrays respectively? - Answer 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?
[runrig]: (of the Sun)
[runrig]: Is happening now...will get to about 70% where I am
[LanX]: enjoy :)

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2017-08-21 17:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Who is your favorite scientist and why?



























    Results (324 votes). Check out past polls.

    Notices?