???紵 发表于 2017-5-17 10:32:05

Perl-Input and Output

Perl-Input and Output

1.printf 格式化输出:

print "Please input the value of width:\n";
chmop( $width = <STDIN> );
print "Please input the content of string:\n";
chmop ( @string = <STDIN> );
print "1234567890" x (($width+9)/10,"12345";
foreach my $lines (@string){
printf "%${width}s\n", $lines;#标量内插,这里要用{}和s分开
}

输入:
Please input the wide:
30
Please input the string:
hewei
good-bye
d
D
12345678901234567890123456789012345
                         hewei
                      good-bye
                           d
                           D
页: [1]
查看完整版本: Perl-Input and Output