The reason why I say my code is a bit better is because:#!/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;
__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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |