in reply to The FizzBuzz Thing :(

choroba made all the right points. Problem is generating an array that doesn’t contain what you think it does and multiple inline print statements where one, without the map, would do. Your answer isn’t bad for someone who is not a hacker and hasn’t touched Perl in 3 years. Good habits and best practices come over time. This was mine from way back when (it does not take advantage of the reuse of the 3/5 to fizz . buzz so it’s not ideal but it is idiomatic :P)–

#!perl -l print !( $_ % 15) ? "FizzBuzz" : !( $_ % 5 ) ? "Buzz" : !( $_ % 3 ) ? "Fizz" : $_ for 1 .. 100;

Replies are listed 'Best First'.
Re^2: The FizzBuzz Thing :(
by Anonymous Monk on Dec 25, 2015 at 21:09 UTC

    Whether the reuse of 3/5 modulo is ideal or not, is itself a contentious point. Codifying it with three conditions is a straight-forward translation of the three rules in the english problem description and arguably carries the logic in clearest of manner. (I suppose the test reveals a bit about your thinking though — grasp of modulo arithmetic, clever vs readable, etc.)

      :( I enjoy overly idiomatic code and do it for my own nonsense but would not commit that kind of code in production. Harrumph! …well, unless I was mad at somebody… ˇˇˇMarry Christmass!!! More eggnog!