Skip to content

Instantly share code, notes, and snippets.

@zentooo
Created May 13, 2010 16:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zentooo/400054 to your computer and use it in GitHub Desktop.
Save zentooo/400054 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use strict;
use warnings;
my $print_if_multiple_of = sub {
my ($str, $base) = @_;
return sub {
my $num = shift;
return ( $num % $base == 0 ) ? $str : "";
};
};
my $fizz = $print_if_multiple_of->("Fizz", 3);
my $buzz = $print_if_multiple_of->("Buzz", 5);
my $fizzbuzz = sub {
my $num = shift;
return $fizz->($num) . $buzz->($num) || $num;
};
print join("\n", map { $fizzbuzz->($_) } (1..100) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment