I'm using:

$find = Swish->new( "'", # ignore beginning "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'", "'", # ignore ending 'breath every', 5, # words to highlight BEFORE 5, # words to highlight AFTER ); de>

With a call-back function of:

$find->stream(\*DATA, sub { " ... $_[1]<b>$_[2]</b>$_[3] ..." }); while (my $t = $find->match) { print "[[$t]]\n" }

And I get this result:

keywords are: <breath> <every> [[ ... With <b>every</b> form you come You surprise ...]] [[ ... me, hypnotize me << shouldn't be a break here With <b>every</b> ...]] [[ ... <b>breath</b> I take << or here You're depriving, suffocating ...]] [[, choking << here's the rest of the text? Now the time has come when I tell myself There's nothing more I can take Then you show me Does it matter right now If I'm already numb That's what you do to control me ]]

It's tough to realize when words match near each other and to then print out a complete line of text.

In other words, I'm looking for this output:

With <b>every</b> form you come ... hypnotize me With <b>every</b> <b>breath</b> I take You're ...

So the code realizes that "every" and "breath" are near each other so not to print out words on either side twice.

Well, I'll have to work through it on Monday.

Thanks,


In reply to Re: Swish module (was Re: Re: Optimizing regular expressions) by moseley
in thread Optimizing regular expressions by moseley

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.