--On Dienstag, 25. September 2001 15:44 -0800 Michael Fowler
<[EMAIL PROTECTED]> wrote:
> It would? Your variables are off by one. Element 2 in @hitsarray is
> 'the', not 'is'. $fieldnumber is set to 4, but you clearly have
> groupings of 5 words:
true; apologies for late night sloppiness.
>
> @hitsarray = qw(
> this is the first hit
> this is the second hit
> this is the third hit
> );
>
>
> Also, $fieldnumber seems to me misnamed; it should be a length, not a
> number.
>
> So, given that, one solution is:
>
> $excerpt_len = 5;
> $search_pos = 1;
>
> @hitsarray = qw(
> this is the first hit
> this is the second hit
> this is the third hit
> );
>
> for (my $i = 0; $i < @hitsarray; $i += $excerpt_len) {
> my $val = $hitsarray[$i + $search_pos];
>
> for (my $j = $i + $excerpt_len; $j < @hitsarray; $j +=
> $excerpt_len) { if ($hitsarray[$j + $search_pos] eq $val) {
> print(
> "Match! ",
> "\"@hitsarray[$i .. $i + $excerpt_len - 1]\" and ",
> "\"@hitsarray[$j .. $j + $excerpt_len - 1]\"\n",
> );
> }
> }
> }
>
> See? It's a simple matter of math, using indices rather than manually
> splitting up the array.
Thank you very much for the code.
The reason why I thought to manually split up the array was that I then
want to print out elements of @hits WITHOUT printing those instances where
there's such a duplicate. I don't know, whether, and if so, how this could
be done just using indices.
This is for a CGI script that I am using to search flatfile databases and
that prints out results in HTML. I don't want to do such a "selective
duplicate check" whenever a search takes place, but only when a particular
name-value-pair is present in the query-string. Therefore I thought to code
a subroutine:
sub view_success {
my @hits = @_;
if ($in{'duplicate_check'}) {
my @hits = &duplicate_check(@hits);
}
# print out @hits
}
> Given the oddity of this request, and the previous request, what is it
> this whole thing is intended to accomplish?
As the above might have revealed, I am trying to add new facilities to a
script that already exists.
The presumably odd nature of my queries results from the fact that I am
trying to operate within the restrictions presented by already extant code.
I don't have enough confidence in my perl skills yet to rewrite the script
on a larger scale.
At present I am therefore trying to solve problems on a "micro-scale",
finding answers to "how can I process sets of n elements of an array"
rather than "how can I carry out a search operation and check for duplicate
values in one particular field". I am taking note of simpler large-scale
approaches for eventual future re-coding of the entire script, so your
suggestsion to pass array references rather than arrays has been duly taken
note of. But I cannot implement it at the present stage, due to competence
and also time restrictions.
Birgit Kellner
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]