in reply to Re^4: Exact string matching
in thread Exact string matching
... and this approach can easily be extended to make n dynamic by interpolating the width counts in the unpack template string.
>perl -wMstrict -le "my $text = 'howdoidoit'; ;; my $n = 3; my $back = $n - 1; ;; my @unpacked = unpack qq{(a$n X$back)*}, $text; my %count; $count{$_}++ for @unpacked[0 .. $#unpacked - $back]; ;; use Data::Dumper; print Dumper \%count; " $VAR1 = { 'wdo' => 1, 'ido' => 1, 'owd' => 1, 'how' => 1, 'oid' => 1, 'oit' => 1, 'doi' => 2 };
|
|---|