Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

Just iterate the combinations of words from the string:

#! perl -slw use strict; # my %hash = ...; my $str = 'Hi this is the sample string for string search'; my @words = split ' ', $str; for my $start ( 0 .. $#words - 1 ) { for my $end ( $start .. $#words ) { print "Lookup: ", join ' ', @words[ $start .. $end ]; } } __END__ C:\test>1001794 Lookup: Hi Lookup: Hi this Lookup: Hi this is Lookup: Hi this is the Lookup: Hi this is the sample Lookup: Hi this is the sample string Lookup: Hi this is the sample string for Lookup: Hi this is the sample string for string Lookup: Hi this is the sample string for string search Lookup: this Lookup: this is Lookup: this is the Lookup: this is the sample Lookup: this is the sample string Lookup: this is the sample string for Lookup: this is the sample string for string Lookup: this is the sample string for string search Lookup: is Lookup: is the Lookup: is the sample Lookup: is the sample string Lookup: is the sample string for Lookup: is the sample string for string Lookup: is the sample string for string search Lookup: the Lookup: the sample Lookup: the sample string Lookup: the sample string for Lookup: the sample string for string Lookup: the sample string for string search Lookup: sample Lookup: sample string Lookup: sample string for Lookup: sample string for string Lookup: sample string for string search Lookup: string Lookup: string for Lookup: string for string Lookup: string for string search Lookup: for Lookup: for string Lookup: for string search Lookup: string Lookup: string search

Where words (or word combinations) appear twice in the string, they will be looked up twice, but that will be faster than de-duplicating the combinations.

Whether that is a problem will depend on whether you consider the same word or phrase appearing in different places duplicates or not; and what you are doing with the information you are generating.


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.

RIP Neil Armstrong


In reply to Re: String Search by BrowserUk
in thread String Search by Sishanth

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others chanting in the Monastery: (16)
    As of 2014-07-30 17:00 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:









      Results (237 votes), past polls