use strict; use warnings; my $num = shift @ARGV; if(!defined $num or $num =~ /[^0-9]/){ die "引数に数値を入力してください。\n"; } my $cnt = 1; my $try_c = 1; #3の倍数カウンタ my $pent_c = 1; #5の倍数カウンタ while($cnt <= $num){ my $out =""; if($try_c == 0){ $out .= "Fizz"; } if($pent_c == 0){ $out .= "Buzz"; } unless($out){ $out = $cnt; } print $out,"\n"; $cnt++; $try_c++; $pent_c++; if($try_c == 3){ $try_c = 0; } if($pent_c == 5){ $pent_c = 0; } }