in reply to How keep the count...
Cheers - L~Rmy @offsets; while ( my $line = <INPUT> ) { chomp $line; my @words = split " ", $line; next if ! grep {$_ eq 'lazy'} @words && ! grep {$_ eq 'dog'} @word +s; my $first; for ( 0 .. $#words ) { my $word = $words[$_]; if ( $word eq 'dog' || $word eq 'lazy' ) { if ( $first ) { push @offsets, $_ - $first + 1; $first = 0; last; } $first = $_; } } } print "The number of matches is : ", scalar @offsets, "\n"; print "The offesets are :\n"; print "$_\n" for @offsets;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: How keep the count...
by Anonymous Monk on Mar 03, 2004 at 17:00 UTC | |
by Limbic~Region (Chancellor) on Mar 03, 2004 at 17:10 UTC | |
by Anonymous Monk on Mar 03, 2004 at 18:47 UTC |