Skip to content

Instantly share code, notes, and snippets.

@mshock mshock/fizzbuzz.pl
Created Apr 27, 2015

Embed
What would you like to do?
fizzbuzz in Perl using a generator
#! perl -w
use strict;
use List::Gen;
my $range;
$range = cache gen {$_} range 1, 100;
sub fizzbuzz {
my ($range, $triggers) = @_;
while (my $num = $range->next) {
my $res;
foreach my $trigger (@$triggers) {
my ($text, $divisor) = @$trigger;
$res = $text if $num % $divisor == 0;
}
print $res ? $res : $num, "\n";
}
}
fizzbuzz($range, [['fizz', 3], ['buzz', 5]]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.