in reply to Elfproef (Dutch bank account check)

Not that it matters unless I'm missing something, but why not:
foreach (1..9)) { $sum += (substr($account, $_-1, 1) * $_); }
?

  p

Replies are listed 'Best First'.
Re: Re: Elfproef (Dutch bank account check)
by Treenaks (Initiate) on Jul 28, 2001 at 21:39 UTC
    Because you have to multiply the last number by 1, the second to last by 2, etc.
    $sum += (substr($account, $_-1, 1) * $_);
    multiplies the first by 1, the second by 2 (the wrong way around :)
      Oh, right.  I guess the only simplification would be
      $sum += substr($account, -$_, 1) * $_;
      Anyway, good code.

        p