Dear Monks, My question is about a faster way to do phrase matching in a sentence. + The usual standard way would be: $sentence="Jack and Jill went up the hill to fetch a pail of water."; $sentence=~/pail of water/\#pail of water\#/g; #tag the phrase 'pail o +f water' in the sentence. However, the above method becomes too slow when I have a long list of +phrases and also sentences. If I have single words instead of phrases +, I could use hash matching on 'split' sentence words, such as: @temp=split(' ', $sentence); my %hash=("pail of water"=>1); foreach my $i (@temp) { if ($hash{$i}) { --- } } However, this method cannot be applied to phrases. Can something simil +ar/faster be used for phrase tagging of sentences? On a related note, how to club the words of the marked phrase in the s +entence as a single unit (i.e. the phrase appears in a single array e +lement when the split is done on the sentence on the space character) +. Thanks.

In reply to phrase marking by newbio

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.