Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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) );
Add Comment
Please, Sign In to add comment