Perl FizzBuzz


Yet another one in Perl.

Code:

#!/usr/bin/perl

for ($i = 1; $i < 100; $i++) {
        if ($i % 15 == 0) { print "FizzBuzz" }
        elsif ($i % 3 == 0) { print "Fizz" }
        elsif ($i % 5 == 0) { print "Buzz" }
        else { print $i }
        print " "
}

2 Responses to “Perl FizzBuzz”

  1. Sean Says:

    You’ve got a whole more line than you need there…

  2. Bob Says:

    You can do it in Perl in 48 characters:

    print+(Fizz)[$_%3].(Buzz)[$_%5]||$_,$/for 1..100

Leave a Reply