in reply to How do you find duplicates in a string?
In this particular example, since the words are tab-separated, I'd probably use a brute-force approach and split the string, then step through the resulting array, incrementing a hash. Admittedly, this is not a very efficient solution for any significant amount of data.
use strict; use warnings; my $string = 'LOCAL Antony 17 Antony 23 1569'; my @tokens = split /\t/,$string; my %duphash = (); foreach (@tokens) { $duphash{$_}++; }
Now %duphash has a 1 for each unique value and something greater than 1 for any duplicates.
Update: I ignored your requirement for skipping over numbers -- adjust accordingly.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How do you find duplicates in a string?
by jdporter (Paladin) on Sep 21, 2006 at 16:37 UTC | |
by Anonymous Monk on Sep 21, 2006 at 16:54 UTC | |
by davido (Cardinal) on Sep 21, 2006 at 18:50 UTC | |
by mk. (Friar) on Sep 21, 2006 at 17:27 UTC | |
by jdporter (Paladin) on Sep 21, 2006 at 20:17 UTC |