I've tried to improve your code, and I have tested what I am posting here.

You have a couple of problems. The first one is that you are creating a number of unnecessary arrays with your extra foreach loops. I've tried to optimize that by using keys with hashes as opposed to creating temporary lookup arrays, and then creating a subroutine to handle reading in the files, etc. When you're done with a file, it is a good idea to close it to avoid leaving dangling filehandles.

The other thing has already been pointed out. If you look at the Lingua::EN::MatchNames documentation, you can see it expects fn1, ln1, fn1, ln2. I fixed that, kind of (see my comment). The name_eq() function will return undef if there is no possible match, so I adding handling for that as well. That accounts for the "uninitialized value" warnings.

#!/usr/bin/perl use strict; use warnings; use Lingua::EN::MatchNames; my $termfile = shift; my $userfile = shift || die "Usage: $0 TERMFILE USERFILE\n"; my %curlookup = getlist($userfile); my %termlookup = getlist($termfile); open my $dfh, ">", "dup.$userfile"); foreach my $termusername (keys %termlookup) { NameComp( $termlookup{$termusername} ) } close $dfh; # getlist takes a filename as an argument sub getlist { my $filename = shift; my $counter; my %results; open my $fh, "<", "$filename"; while ( <$fh> ) { chomp; ++$counter; next unless m/[A-Za-z]/; $results{$counter} = $_; print "Adding user $counter $_ from file \'$filename\' to hash +\n"; } close $fh; return %results; } sub NameComp { # no parens, this is not a function prototype my $compname = shift; foreach my $curusername (keys %curlookup) { print "Comparing \'$compname\' to \'$curlookup{$curusername}\' +\n"; # This method is not good because it assumes a ' FN -SPACE- LN + ' format my @compname = split /\s+/, $compname; my @curname = split /\s+/, $curlookup{$curusername}; my $name_score = name_eq( $compname[0], $compname[1], +$curname[0], $curname[1] ); if ( $name_score ) { if ( $name_score >= 80 ) { print "Found Match $curlookup{$curusername} with a sco +re of $name_score.\n\n"; } } else { print "\t\tNo possible match.\n\n"; } } }

Best of luck to you.

--
Damon Allen Davison
http://www.allolex.net


In reply to Re: Memory Leak when using Lingua::EN::MatchNames by allolex
in thread Memory Leak when using Lingua::EN::MatchNames by Cincyman

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.