dave_pl has asked for the wisdom of the Perl Monks concerning the following question:
--------------END---------------#!usr/bin/perl.exe $a = 0; open(DUP, ">Duplicates found.csv") || die $!; open(NOR, ">Not in main.csv") || die $!; open(FILEM, "main.csv"); open(FILET, "tmp1.csv"); @file1 = <FILEM>; @file2 = <FILET>; foreach $item(@file1){ $item =~ /(\d[0-9]{6,15}\d)/; $val = &bin_search( \@file2, $1 ); #Here are some example of the first line n @file2[1] #East Rd,GouisS Lees & PARTNERS, 12345678/1,JACOBS #and $1 is a example of 12345678 but it doesn`t match if(defined $val){ print DUP "$item"; } } close(FILEM); close(FILET); close(NOR); close(DUP); sub bin_search { my ($file2, $word) = @_; my ($low, $high) = ( 0, @$file2 - 1 ); while ( $low <= $high ) { # While the window is open my $try = int( ($low+$high) /2 ); # Try the middle element $low = $try+1, next if $array->[$try] lt $word; # Raise bottom $high = $try-1, next if $array->[$try] gt $word; # Lower top return $try; # We've found the word! } return; } }
20050404 Edit by ysth: code tags; remove unneeded brs from text paragraph
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Binary Search
by borisz (Canon) on Apr 04, 2005 at 13:06 UTC | |
Re: Binary Search
by dragonchild (Archbishop) on Apr 04, 2005 at 13:12 UTC | |
by dave_pl (Sexton) on Apr 04, 2005 at 14:01 UTC | |
by dragonchild (Archbishop) on Apr 04, 2005 at 14:16 UTC | |
Re: Binary Search
by Jaap (Curate) on Apr 04, 2005 at 13:10 UTC | |
by dave_pl (Sexton) on Apr 04, 2005 at 13:43 UTC |