花括号的使用 printf %${width}s , 否则会 去找 $widths

花括号的使用  printf %${width}s , 否则会 去找  $widths

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

猜你喜欢

转载自www.cnblogs.com/books2read/p/11003874.html