John W. Krahn wrote:
It looks like this will do what you want:
sub score {
my ( $str, $array ) = @_;
my $total_score = 0;
for my $frag ( @$array ) {
my $len = length $frag;
my $idx = index $str, $frag;
if ( $idx >= 0 and substr $str, $idx, $len, '' ) {
$total_score += $len;
}
}
return $total_score;
}
Which can be written more compactly as:
sub score {
my ( $str, $array ) = @_;
my $total_score = 0;
for my $frag ( @$array ) {
( my $idx = index $str, $frag ) >= 0 or next;
$total_score += length substr $str, $idx, length $frag, '';
}
return $total_score;
}
:-)
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>