Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^4: Exact string matching

by BrowserUk (Patriarch)
on Oct 16, 2011 at 20:05 UTC ( [id://931808]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Exact string matching
in thread Exact string matching

The fastest way to n-tuple long strings is using unpack:

$text = 'howdoidoit';; print for unpack '(a3X2)*', $text;; how owd wdo doi oid ido doi oit it it print for unpack '(a4X3)*', $text;; howd owdo wdoi doid oido idoi doit oit oit oit

You have to discard the last n-1 results but that is very quick and simple to do.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^5: Exact string matching
by AnomalousMonk (Archbishop) on Oct 16, 2011 at 23:29 UTC

    ... 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 };

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://931808]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-18 18:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found