|
发表于 2004-6-15 17:44:54
|
显示全部楼层
[php]
#!/usr/bin/perl -w
use POSIX;
open FP, ">log.txt";
select(FP);
sub print_line
{
my($line, $dim, $col) = @_;
$col = $col|| 80; #the terminal width, default 80 characters.
return if($col > 80);
my $count = ceil($col/2)-$line;
print " " x $count, '1 ' x $line, "\n";
}
my $dim = 11;
for(my $i=1; $i <= ceil($dim/2); $i++){
print_line($i, $dim);
}
for(my $i=floor($dim/2); $i>0; $i--){
print_line($i, $dim);
}
close(FP);
[/php]
输出:
- 1
- 1 1
- 1 1 1
- 1 1 1 1
- 1 1 1 1 1
- 1 1 1 1 1 1
- 1 1 1 1 1
- 1 1 1 1
- 1 1 1
- 1 1
- 1
复制代码 |
|