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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |