On Fri, 2004-04-16 at 10:56, David Wheeler wrote:
> On Apr 16, 2004, at 7:19 AM, Simon Cozens wrote:
> 
> > I'll bet you the actual most *common* use of modulus is:
[...]
> >         print $percent_done,"\n" unless $percent_done % 10;

> And I'll bet it's something like this:
>      my $css_class = $i % 2 ? 'blue' : 'yellow';

Those are both the same, really. In the first case:

        do_every(10, $percent_done, sub {print $percent_done, "\n"});

where the second is:

        do_every(2, $i, sub {$css_class = 'blue'}, sub {$css_class = 'yellow'});

Only a subtle variation. do_every would look like:

        sub do_every(int $n, int $current, code $doit, code $elsedoit = undef) {
                if $n % $current == 0 {
                        $doit();
                } elsif defined $elsedoit {
                        $elsedoit();
                }
        }

-- 
Aaron Sherman <[EMAIL PROTECTED]>
Senior Systems Engineer and Toolsmith
"It's the sound of a satellite saying, 'get me down!'" -Shriekback


Reply via email to