﹝學習記錄﹞- Perl – 畫星星 ✩✩✩
指定範圍畫星星…
執行程式範例:
Please enter a value of width(1-100): 44 Please enter a value of height(1-30): 5
******************************************** ******************************************** ******************************************** ******************************************** ******************************************** |
程式碼:
my $v1=1; my $v2=1; my $val_w; my $val_h; while ($v1==1){ print "Please enter a value of width(1-100): "; chomp($val_w=<>); $v1=0; if($val_w<=0 or $val_w>100 or $val_w != int($val_w)){ $v1=1; } } while ($v2==1){ print "Please enter a value of height(1-30): "; chomp($val_h=<>); $v2=0; if($val_h<=0 or $val_h>30 or $val_h != int($val_h)){ $v2=1; } } print "\n"; for (my $i=1;$i<=$val_h;$i++){ print '*'x $val_w,"\n"; } print "\n"; |
留言列表