http://www.perlmonks.org?node_id=968215


in reply to Re: While two conditions
in thread While two conditions

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>)