in reply to Finding common substrings
or, less verbose,$a = 'PF01389 6 218 1 255 430.09'; $b = 'PF00691 PF01389'; my %counts; foreach ( split /\s+/, $a ) { $counts{$_} = 1; } foreach ( split /\s+/, $b ) { $counts{$_}++ if exists $counts{$_}; } my @common = grep $counts{$_} > 1, keys %counts; if ( @common ) { print "correct\n"; }
$a = 'PF01389 6 218 1 255 430.09'; $b = 'PF00691 PF01389'; my %in_a = map { $_ => 1 } split /\s+/, $a; my @in_both = grep { exists $in_a{$_} } split /\s+/, $b; if ( @in_both ) { print "correct\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Finding common substrings
by ktsirig (Sexton) on Sep 20, 2006 at 22:46 UTC | |
|
Re^2: Finding common substrings
by johngg (Canon) on Sep 21, 2006 at 09:19 UTC | |
by mreece (Friar) on Sep 21, 2006 at 16:36 UTC | |
by johngg (Canon) on Sep 21, 2006 at 20:50 UTC |