I am adapting Lingua::Concordance. It takes all occurences of $query and show it with its context in a ordered way.

Here is the code

$text="Oldfield's career began fairly early, playing <1> acoustic guit +ar in local folk clubs. At this time, he already had two fifteen-minu +te instrumental pieces in which he would "go through all <2>sorts of +moods", precursors to his landmark 1970s' compositions. In his early +teens, Oldfield was involved in a 'beat group' <3>playing Shadows-sty +le music (he has often cited Hank Marvin as a major influence, and wo +uld later cover The Shadows' song "Wonderful Land")." $query="in"; while ( $text =~ /$query/gi ) { my $match = $1; my $pos = pos( $text ); my $start = $pos - $self->radius - length( $match ); my $extract = ''; if ( $start < 0 ) { $extract = substr( $text, 0, $width + $start + length( $ma +tch )); $extract = ( " " x -$start ) . $extract; } else { $extract = substr( $text, $start, $width + length( $match +)); my $deficit = $width + length( $match ) - length( $extract + ); if ( $deficit > 0 ) { $extract .= ( " " x $deficit ) } } push @lines, $extract; }

What I am trying to do is to read the <> tag and associate it to the corresponding $extract (for example: "guitar in local folk" seen after <1>)


In reply to Re^2: While two conditions by welle
in thread While two conditions by welle

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.