花括号的使用 printf %${width}s , 否则会 去找 $widths
1 #! /usr/bin/perl
2 use strict;
3 use warnings;
4
5 =head1
6 print "
----------------------------------ch_5_Q1_--------------------------
";
7 #print reverse <>;
8 print "
----------------------------------_--------------------------
";
9 select STDIN;
10 my @single_quotation = <>;
11 print @single_quotation;
12 print "
----------------------------------ch_5_Q1_--------------------------
";
13 =cut
14
15 print "
----------------------------------ch_5_Q2_--------------------------
";
16 print "What column width would you like?, please input:";
17 chomp(my $width = <STDIN>);
18 print "Enter some lines, then press Ctrl-D:
"; # or Ctrl-z
19 my @underscore;
20 chomp(@underscore = <STDIN>);
21 #@underscore = <STDIN>;
22 #print "
"."1234567890"x7,"12345
";
23 print "
"."1234567890"x (($width + 9)/10),"12345
";
24
25 =head1
26 foreach(@underscore){
27 #print "$_"."
";
28 printf "%20s
", $_;
29 }
30 =cut
31
32 my $semicolons = "%${width}s
" x @underscore;
33 printf "$semicolons", @underscore;
34 print "
----------------------------------ch_5_Q2_--------------------------
";