<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hi,<div>Kris B had a really good idea for this problem, since the names identify items that do get repeated many times:</div><div><div>names1 contains 46227 names.</div><div>names2 contains 5726 names.</div><div>class1 contains 7815 names.</div><div>class2 contains 748 names.</div><div><br></div><div>Much faster.</div><div><br></div><div>Thanks!</div><div><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><div>On Nov 4, 2011, at 3:39 PM, Kris Bosland wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">I would suggest smashing the strings into classes and then you only have to make comparisons within the classes.<div><br></div><div>For example, you could find the Soundex(tm) code of each name.</div><div><br></div><div>I don't know the details of your naming conventions so you would need to figure out the algorithm to get all the possible matches into one class - false positives are fine (a larger class but still small compared to your bigger set) but you don't want false negatives (putting things in different classes from each other).</div>
<div><br></div><div>My $0.002</div><div><br></div><div><lurk/></div><div><br></div><div>-Kris<br><br><div class="gmail_quote">2011/11/4 Tom Keller <span dir="ltr"><<a href="mailto:kellert@ohsu.edu">kellert@ohsu.edu</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div style="word-wrap:break-word">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 style="white-space:pre-wrap">    </span>my $c = $_;</div><div><span style="white-space:pre-wrap">      </span>if ( $c > $#names1  or <span style="white-space:pre-wrap">         </span># always false</div>
<div><span style="white-space:pre-wrap">          </span>( grep { $names1[$c] =~ m/$_/ } @out ) > 0) {</div><div><span style="white-space:pre-wrap">         </span>1;  ## save</div><div><span style="white-space:pre-wrap"> </span>} else {</div>
<div><span style="white-space:pre-wrap">          </span>0;  ## skip</div><div><span style="white-space:pre-wrap"> </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>
Tom<br><a href="http://www.ohsu.edu/xd/research/research-cores/dna-analysis/" target="_blank">MMI DNA Services Core Facility</a><br><a href="tel:503-494-2442" value="+15034942442" target="_blank">503-494-2442</a><br>kellert at <a href="http://ohsu.edu/" target="_blank">ohsu.edu</a><br>
Office: 6588 RJH (CROET/BasicScience)<br><br><a href="http://www.ohsu.edu/xd/research/research-cores/index.cfm" target="_blank">OHSU Shared Resources</a><br><br><br><br><br><br>
</div>
<br></div></div><br>_______________________________________________<br>
Pdx-pm-list mailing list<br>
<a href="mailto:Pdx-pm-list@pm.org">Pdx-pm-list@pm.org</a><br>
<a href="http://mail.pm.org/mailman/listinfo/pdx-pm-list" target="_blank">http://mail.pm.org/mailman/listinfo/pdx-pm-list</a><br></blockquote></div><br></div>
</blockquote></div><br></div></div></body></html>