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).
This is the code I have so far:
my $text ="this is just some text I am making up as an example but it
should be a bit longer since I am testing this script and would like to use
larger numbers";
print "your searchstring: ";
chomp ($searchstring = <STDIN>);
print "number: ";
chomp ($col = <STDIN>);
for ($i = -$col; $i <= +$col; $i++) { push (@cols, $i); } # create array of
all numbers
#between 0 and $col
(positive and negative)
# if $col=4, then
we get the range from -4 to 4
@text = split / /, $text;
# 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";}
}
## if $found_index is the index number of the array-element which matches
$searchstring -
foreach $col(@cols) {
push (@searchstring, $text[$found_index + $col])
}
If I use "making" as $searchstring, the print statement returns:
"index value of making is 0.
index value of making is 1.
index value of making is 2.
index value of making is 3.
index value of making is 4.
index value of making is 5.
index value of making is 6."
Help will be greatly appreciated,
Birgit Kellner
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]