On 3/3/06, Ryan Gies <[EMAIL PROTECTED]> wrote: > > Ash Varma wrote: > > > > Any hint on the J Smith and J Smith Thomas ?? > > > > Hmm, good point. I'm sure there are several methods, but the first > which comes to mind is to do two replacements... > > a. sort you list by the length(), processing longer names first > b. 1st replacement replaces the all names with their unique id > > ... J Smith ___ J Smithers ___ J Smith Thomas ... > > becomes > > ... {{0001}} ___ {{0002}} ___ {{0003}} ... > > c. 2nd replacement puts the names back in > > ... {{0001}} ___ {{0002}} ___ {{0003}} ... > > becomes > > ... J Smith 00001 ___ J Smithers 0002 ___ J Smith Thomas 0003 ... > > > For example: > > > !/usr/bin/perl -w > > my @names = ( 'J Smith', 'J Smithers', 'J Smith Thomas' ); > my $text = "... J Smith ___ J Smithers ___ J Smith Thomas ..."; > my %id_to_name = (); > my $idx = 0; > > foreach my $name ( sort { length($b) <=> length($a) } @names ) { > > my $playerid = sprintf "%04d", ++$idx; > $id_to_name{$playerid} = $name; > $text =~ s/\b$name\b/{{$playerid}}/g; > > }#foreach > > print "$text\n"; > > foreach my $id ( keys %id_to_name ) { > > $text =~ s/\{\{$id\}\}/$id_to_name{$id} $id/g; > > }#foreach > > print "$text\n";
Brilliant !!! I'll try this.. But this makes very good sense.. and should work quite well for me :) Thanks again Ash -- Ash Varma [EMAIL PROTECTED] [EMAIL PROTECTED] The browser you can trust! Get Firefox and rediscover the web! http://www.getfirefox.com/