in reply to Easy binary toggle at fixed intervals

Sexy! I likey a lot. Still, I had to tinker...
#!/usr/bin/perl -w use strict; my $cycle = initToggle( 3 ); for (1..24) { print "$_ " . &$cycle . "\n"; } sub initToggle { my $limit = shift; die "initToggle() requires a non-zero integer\n" if ($limit == 0 or int($limit) != $limit); my $count = -1; my $bit = $limit >0 ? 0 : 1; $limit = abs($limit); return sub { $bit ^=1 if (++$count % $limit == 0); return $bit; } }

Now you can flip the bit on creation and you check for initToggle ( 3.333 );

--
$you = new YOU;
honk() if $you->love(perl)