--On Donnerstag, 26. Juli 2001 04:15 +0200 Birgit Kellner
<[EMAIL PROTECTED]> wrote:
> Hi,
>
> I'm thinking of coding a KWIC search through a text. The user chooses a
> search string and a horizon, meaning that output is to contain $i words
> to the left and to the right of the search string (if found).
>
...
># the next block is my problem. it should return the index
># number of that element of array @text which matches $searchstring -
># alas, it doesn't! why?
> for ($i = 0; $i < @text; $i++) {
> last if ($text[$i] =~ /$searchstring/);
> $found_index = $i;
> if ($i < @text)
> { print "index value of $searchstring is $found_index.\n";
> }
> else { print "not found.\n";}
> }
I got it - the syntax of the code in the for-loop had a mistake. It should
be
for ($i = 0; $i < @text; $i++) {
if ($text[$i] =~ /$searchstring/) {
$found_index = $i;
last;}
}
Now $found_index contains the index number of that element of @text which
matches $searchstring.
Birgit
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]