Dear Monks,

Thank you very much every one. I didn't expect this many replies.

=>Ram:By Linear time I means O(n), which deals with time complexity.

=>BrowserUK & AnomalousMonk:Thank you very much guys that was a very gud kick start.

So as BrowseUK and AnomalousMonk suggested I have attached the script, which I have modified as per the requirements but the problem with this is it took 3mins to run on a file sized only 7 MB. this is not efficient as I have to deal with file sized over GB's. So now how do I optimize it for file sized over GB's or is there any other efficient way to accomplished this.

Note: I have noticed that using an array slows down the run time.Isn't much a big discovery, but can we use any alternate.
use List::MoreUtils qw(uniq); open(HD,"File") or die ("Cant open"); $text=<HD>; chomp $text; my $n = 6; my $back = $n - 1; my @array = unpack qq{(a$n X$back)*}, $text; @unpacked=uniq @array; for($i=0;$i<=$#unpacked-$back;$i++) { $pattern= $unpacked[$i]; $offset = 0; print "\n$pattern ($n)\n"; print '~' x $n,"\n"; $pos=index $text,$pattern,$offset; while ($pos != -1) { print $pos+1," to ",$pos+$n,"\n"; $offset = $pos + 1; $pos = index($text, $pattern, $offset); } }

In reply to Re: Exact string matching by saranrsm
in thread Exact string matching by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.