EdwardG,
Ok - I interpreted the requirement differently. Since there are only two possibilities and "Ad Ha" can only refer to 1, "A H" must refer to the other. I believe the following accomplishes what you want - and is actually a bit better than your solution (I think). If I am wrong - I give up.
#!/usr/bin/perl
use strict;
use warnings;
my %data;
my $last = 0;
while ( <DATA> ) {
chomp;
my @names = split;
$last = @names if @names > $last;
$_ = ucfirst lc $_ for @names;
$data{ "@names" } = \@names;
}
for my $index ( 0 .. $last ) {
for my $person ( keys %data ) {
next if ! $data{$person}[$index];
my $old_name = $data{$person}[$index];
for my $length ( 1 .. length $old_name ) {
$data{$person}[$index] = substr( $old_name, 0, $length );
my $match = 0;
for ( keys %data ) {
next if $_ eq $person || @{$data{$_}} != @{$data{$pers
+on}};
my $test_name = $data{$_}[$index];
$data{$_}[$index] = substr( $test_name, 0, $length );
my ($s_name , $s_test) = ("@{$data{$person}}", "@{$dat
+a{$_}}");
$data{$_}[$index] = $test_name;
if ( $s_name eq $s_test ) {
$match = 1;
last;
}
}
last if ! $match;
}
}
}
print "@{ $data{$_} } =>\n" for keys %data;
The reason why I say my code is a bit better is because:
__DATA__
Victor Mcduffie
Viola Mcnamee
# Yours
Vic Mcd
Vio Mcn
# Mine
V Mcn
V Mcd
Cheers - L~R
|