Re: Hi, how to extract five texts on each side of an URI? I post my own perl script and its use.
- From: Jenda@xxxxxxxxxxx (Jenda Krynicky)
- Date: Tue, 14 Nov 2006 14:34:33 +0100
From: ťÔ Íő <whui05@xxxxxxxxxxxx>
my $text;
for my $left_index (1..WIDTH) {
last if $start_index < $left_index;
$text .= $texts_arr[$start_index - $left_index] . ' ';
}
$text .= join(" ", @texts_arr[$start_index..$end_index]) . ' ';
for my $right_index (1..WIDTH) {
last if $end_index + $right_index > $#texts_arr;
$text .= $texts_arr[$end_index + $right_index] . ' ';
}
$text_hash{$url} = $text;
As far as I can tell this could easily be rewriten with no loops. If
I understand it correctly you want to get all the texts from
$start_index-WIDTH to $end_index+WIDTH so something like:
my $left_index = $start_index - WIDTH;
$left_index = 0 if $left_index < 0;
my $right_index = $end_index + WIDTH;
$right_index = $#texts_arr if $right_index > $#texts_arr;
my $text = join(" ", @texts_arr[$left_index .. $right_index]);
should do what you are after. There are probable other things, but
this caught my eyes.
Jenda
===== Jenda@xxxxxxxxxxx === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery
.
- References:
- Prev by Date: Re: How to define modules?
- Next by Date: Unexpected end of processing
- Previous by thread: RE: Hi, how to extract five texts on each side of an URI? I post my own perl script and its use.
- Next by thread: Hi, how to extract five texts on each side of an URI? I post my own perl script and its use.
- Index(es):
Relevant Pages
|
|