walkingthecow has asked for the wisdom of the Perl Monks concerning the following question:
open(NAMEDB, "/home/daamaya/database.csv"); @people=<NAMEDB>; close (NAMEDB);
@gecos_split=split(/,/,$gecos); $new_gecos = &cleanGECOS($gecos_split[0]); $current_group=`grep ":$gid:" /users/oss/users/gro +up/$server_name.grp | cut -d : -f 1`; chomp($current_group); $current_group=uc($current_group); @names = $new_gecos; for $name (@names) { @comps = $name =~ m{(?:von|de la|de|van|der|le +|el|la).*|\w+}g; } @names = @comps; if ($names[0]) { @exact_match=grep{/^$new_gecos&/}@people; chomp(@exact_match); } if (!@exact_match) { if ($names[0] && $names[1] && $names[2]) { @approx_match=grep{/$names[0]/ && /$names[ +1]/ && /$names[2]/i}@people; chomp(@approx_match); } if (!@approx_match) { if ($names[2] eq "") { $names[2] = $names[1]; $names[1] = ""; } @approx_match=grep{/$names[0]/ && /$names[2]/i +}@people; chomp(@approx_match); } else { # print "Nothing in GECOS field\n"; } } if (@exact_match) { chomp($exact_match[0]); @exact_breakdown=split(/,/,$exact_match[0]); $gecos_new="$exact_breakdown[0],$current_group +,$exact_breakdown[1],$exact_breakdown[2]"; chomp($gecos_new); @exact_match = (); } elsif (@approx_match == 1) { chomp($approx_match[0]); @approx_breakdown=split(/,/,$approx_match[0]); $gecos_new="$approx_breakdown[0],$current_grou +p,$approx_breakdown[1],$approx_breakdown[2]"; chomp($gecos_new); @approx_match = (); } elsif (@approx_match) { for ($n=0; $n < @approx_match; $n++) { print "MATCH [$n] :: << @approx_match[$n] +>> \n"; } } else { print "NO-MATCH in database :: << $new_gecos >> + \n\n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Best way to search content of an array
by GrandFather (Saint) on Sep 02, 2008 at 01:43 UTC | |
|
Re: Best way to search content of an array
by jethro (Monsignor) on Sep 02, 2008 at 09:35 UTC |