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


In reply to Re: Re: Re: Re: Re: Generate unique initials from a list of names by Limbic~Region
in thread Generate unique initials from a list of names by EdwardG

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.