First of all, here the context for the unaware Fizz_buzz

> If I did this in an interview, would you hire me?

no yet, because it's only an entry filter

Fizz buzz (often spelled FizzBuzz in this context) has been used as an interview screening device for computer programmers. Writing a program to output the first 100 FizzBuzz numbers is a relatively trivial problem requiring little more than a loop and conditional statements in any popular language, and is thus a quick way to weed out applicants with absolutely no programming experience.

(from the WP article, emphasize added)

> What techniques for making my code more compact and less maintainable have I overlooked?

TIMTOWTDI

for short idomatic Perl you could just stack the "Fuzz" behind the "Bizz" for the "double case"

for my $i (1..100) { my $result; $result .= "Fizz" unless $i % 3; $result .= "Buzz" unless $i % 5; $result //= $i; # "unless defined $result;" print "$result\t\t"; print "\n" unless $i % 5; # that's just sugar for nicer tabul +ar view }

the vanilla approach is to use if-elsif-else-chains

for my $i (1..100) { if ( not $i % 15 ) { print "FizzBuzz"; } elsif ( not $i % 3 ) { print "Fizz"; } elsif ( not $i % 5 ) { print "Buzz"; } else { print $i; } print "\t\t"; print "\n" unless $i % 5; # that's just sugar for nicer tabular v +iew }

Cheers Rolf
(addicted to the Perl Programming Language :)
see Wikisyntax for the Monastery


In reply to Re: Rate my fizzbuzz by LanX
in thread Rate my fizzbuzz by Vonunov

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.