Wagner, David --- Senior Programmer Analyst --- WGO wrote:
John W. Krahn wrote:

Wagner, David --- Senior Programmer Analyst --- WGO wrote:

Since you are not using the offset, and you have the same value GG twice and index starts over from the first, you are counting the same GG twice. If you remove the last GG, you will still come up with 4 and it should be 2 unless I am missing something.

I think that you are missing something. :-) Did you try the code?

I missed that you were deleting what you found as you worked along.

Right, since $str is a local copy in the sub it is alright to modify it which ensures that the same substring is not found twice. Another way to do it:

sub score {
  my ( $str, $array ) = @_;
  my $total_score = 0;

  for my $frag ( @$array ) {
    $total_score += length $frag if $str =~ s/\Q$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>




Reply via email to