<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Greetings,<div>I have two very long lists of names. They have slightly different conventions for naming the same thing, so I devised a regex to compare the two lists. I need to extract the names common to both. (Acknowledgement: "Effective Perl Programming, 1st ed.")</div><div>But it is taking an ungodly amount of time, since </div><div><div>names1 contains 46227 names.</div><div>names2 contains 5726 names.</div></div><div><br></div><div>Here's the code:</div><div>########</div><div><div>my @names1 = get_names($file1);</div><div>my @names2 = get_names($file2);</div><div>#say join(", ", @names1);</div><div><br></div><div>my @out = map { $_ =~  m/\w+[-_]*(\w*[-_]*\d+[a-z]*).*/ } @names2;</div><div>my @index = grep {</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>my $c = $_;</div><div><span class="Apple-tab-span" style="white-space:pre">  </span>if ( $c > $#names1  or <span class="Apple-tab-span" style="white-space:pre">             </span># always false</div><div><span class="Apple-tab-span" style="white-space:pre">               </span>( grep { $names1[$c] =~ m/$_/ } @out ) > 0) {</div><div><span class="Apple-tab-span" style="white-space:pre">             </span>1;  ## save</div><div><span class="Apple-tab-span" style="white-space:pre">     </span>} else {</div><div><span class="Apple-tab-span" style="white-space:pre">             </span>0;  ## skip</div><div><span class="Apple-tab-span" style="white-space:pre">     </span>}</div><div>} 0 .. $#names1;</div><div><br></div><div>my @common = map { $names1[$_] } @index;</div></div><div>########</div><div><br></div><div>Is there a faster/better way to do this?</div><div><br></div><div>thanks,<br><div apple-content-edited="true">
Tom<br><a href="http://www.ohsu.edu/xd/research/research-cores/dna-analysis/">MMI DNA Services Core Facility</a><br>503-494-2442<br>kellert at <a href="http://ohsu.edu">ohsu.edu</a><br>Office: 6588 RJH (CROET/BasicScience)<br><br><a href="http://www.ohsu.edu/xd/research/research-cores/index.cfm">OHSU Shared Resources</a><br><br><br><br><br><br>
</div>
<br></div></body></html>