I considered that that may be your requirement, but I thought there were too many unknowns for me to sensibly implement sample code. The most important is what should happen where the last tag seen may be associated with multiple concordance fragments? I chose to only consider tags within the current fragment. Another option would be to reuse a tag for all following fragments until a new tag is found, or a tag could be associated with the first following fragment, or the first following fragment so long as it is within some maximum distance of the tag.

I would first split the text by tag entries, then perform the concordance match on each fragment:

use strict; use warnings; use Lingua::Concordance; my $text = <<TEXT; Oldfield's career began fairly early, playing <1> acoustic guitar in l +ocal folk clubs. At this time, he already had two fifteen-minute instrumental pi +eces in which he would "go through all <2>sorts of moods", precursors to his l +andmark 1970s' compositions. In his early teens, Oldfield was involved in a 'b +eat group' <3>playing Shadows-style music (he has often cited Hank Marvin as a ma +jor influence, and would later cover The Shadows' song "Wonderful Land"). TEXT my $concordance = Lingua::Concordance->new(); $concordance->text($text); my @parts = split /\s*(<\d+>)\s*/, $concordance->text(); my @frags; unshift @parts, '' if $parts[0] !~ /^<\d+>$/; push @frags, map {$_->[0] =~ s/[<>]//; $_} [splice @parts, 0, 2] while + @parts; $concordance->query('in'); for my $fragment (@frags) { my ($tag, $fragText) = @$fragment; $concordance->text($fragText); print "$tag: $_\n" for $concordance->lines(); }

Prints:

: fairly early, playing 1>: acoustic guitar in local folk clubs. A 1>: had two fifteen-minute instrumental pie 1>: wo fifteen-minute instrumental pieces in 1>: strumental pieces in which he would "go 2>: 0s' compositions. In his early teens, Ol 2>: ens, Oldfield was involved in a 'beat gr 2>: ield was involved in a 'beat group' 3>: playing Shadows-style musi 3>: en cited Hank Marvin as a major influenc 3>: Marvin as a major influence, and would l

It should be fairly trivial to modify the loop to meet whatever additional constraints you require.

True laziness is hard work

In reply to Re^5: While two conditions by GrandFather
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.