Re: Hi, how to extract five texts on each side of an URI? I post my own perl script and its use.



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

.



Relevant Pages

  • Re: file.db VS filedb
    ... to get drunk and croon as much as they like. ... -- Terry Pratchett in Sourcery ...
    (perl.beginners)
  • Re: Matching the domain of a URL
    ... foreach my $url { ... to get drunk and croon as much as they like. ... -- Terry Pratchett in Sourcery ...
    (perl.beginners)
  • Re: XML::Rules tests [was: Re: XML::LibXML navigation]
    ... on Linux. ... to get drunk and croon as much as they like. ... -- Terry Pratchett in Sourcery ...
    (perl.beginners)
  • Re: Bug in Perl
    ... here you wiil get output as expected... ... to get drunk and croon as much as they like. ... -- Terry Pratchett in Sourcery ...
    (perl.beginners)
  • Re: RE
    ... It works with the @ as well, but it's misleading. ... to get drunk and croon as much as they like. ... -- Terry Pratchett in Sourcery ...
    (perl.beginners)