in reply to Order Pairs

use Text::Soundex 'soundex'; my @words = qw( Cow Phone Speaker Phone Hello World Phon Speaker Clock Phon Torld Hello Hello Worlx ); while( @words ) { push @pairs, [ shift @words, shift @words ]; } @pairs = map { $_->[1] } sort { $a->[0] cmp $b->[0] } map { [ join( '' => sort { $a cmp $b } ( soundex @$_[0], soundex @$_[1] ) ), $_ ] } @pairs; for( @pairs ) { print "@$_\n"; }

output:

Cow Phone Clock Phon Torld Hello Hello World Hello Worlx Speaker Phone Phon Speaker

Update: I've chosen soundex just because it was very easy to implement.
Other string comparison methods might give better/more exact results.

Replies are listed 'Best First'.
Re: Re: Order Pairs
by diotalevi (Canon) on Jul 01, 2003 at 16:39 UTC

    Soundex works for assisting manual matching on English last names, Metaphone is supposed to be somewhat nicer for that task and is implemented in Text::DoubleMetaphone and Text::Metaphone. But this problem shouldn't be solved with an Enlgish last-name approximation system. Others suggested an edit distance metric like String::Approx.