Li Ngok Lam wrote:
>
> Thanks John, and Rob.
>
> This reply is quite close to what I am going to do,
> but some critical point is wanted here.... I'll try to explain
> my question further....
>
> It does, and thaz about my coding currently up to.....
>
> > #!/usr/bin/perl
> > use warnings;
> > use strict;
> >
> > my @data = qw(
> > 123ABCDEF456
> > 123456
> > 654WXYZ321
> > 987654321
> > ABCDEF123456
> > WXYZ321
> > );
> >
> > for my $x ( @data ) {
> > for my $y ( @data ) {
> > next if $x eq $y or length( $x ) < length( $y );
> > my $count = () = $x =~ /[\Q$y\E]/g;
> > my $perc = ( $count / length $x ) * 100;
> > printf "%-12s %-12s %2d %2d %6.2f %%\n", $x, $y, length $x,
> $count, $perc;
> > }
> > }
> >
> > __END__
> >
> > Produces this output:
> >
> > 123ABCDEF456 123456 12 6 50.00 %
> > 123ABCDEF456 654WXYZ321 12 6 50.00 %
>
> For what I want, this is not a match.
> if my input is 3, than, the scanning process is like this :
>
> 123 compare 654WXYZ321 = false
> 23A compare 654WXYZ321 = false
> 3AB compare 654WXYZ321 = false
> ABC compare 654WXYZ321 = false
> ...
> ...
> 456 cmp 654WXYZ321 = false
>
> In case, 3 means, each 3 chars from the string formed a pattern
> and trying to compare with elems in the list.
Maybe this is closer to what you want:
#!/usr/bin/perl
use warnings;
use strict;
my $len = 3;
my @data = qw(
123ABCDEF456
123456
654WXYZ321
987654321
ABCDEF123456
WXYZ321
);
for my $x ( @data ) {
for my $y ( @data ) {
next if $x eq $y or length( $x ) < length( $y );
my $count;
for ( my $offset; length( my $chunk = substr $y, $offset++, $len ) == $len; ) {
$count += index( $x, $chunk ) >= 0;
}
printf "%-12s %-12s %2d %2d\n", $x, $y, length $x, $count;
}
}
__END__
Produces this output:
123ABCDEF456 123456 12 2
123ABCDEF456 654WXYZ321 12 0
123ABCDEF456 987654321 12 0
123ABCDEF456 ABCDEF123456 12 6
123ABCDEF456 WXYZ321 12 0
654WXYZ321 123456 10 0
654WXYZ321 987654321 10 2
654WXYZ321 WXYZ321 10 5
987654321 123456 9 0
987654321 WXYZ321 9 1
ABCDEF123456 123ABCDEF456 12 6
ABCDEF123456 123456 12 4
ABCDEF123456 654WXYZ321 12 0
ABCDEF123456 987654321 12 0
ABCDEF123456 WXYZ321 12 0
WXYZ321 123456 7 0
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]