#!/user/bin/perl
$max = '30';
$len = '50';
for ($num = 0;$num<=$max;$num++) {
local $| = 1;
$percent = int(($num/$max)*100);
$print = "["."%-"."$len"."s"."] "."%d%%"."r";
$bar = '=' x int(($percent/100)*$len);
if (int(($percent/100)*$len) < $len) {$bar .= '>';}
printf ($print,"$bar","$percent");
sleep (1);
}
print "nSuccess!n";
実際に実行すると下記の様になります。
[root@orbit ~]# perl ber.pl
[=================> ] 26%
0 Comments.