1. Exercise
2. Code and Output
Cat_reverse.pl
1 #-----------------------------------------------------------#
2 # Source: Learning Perl, chapter5, exercise-1
3 # Date: 2012-01-15
4 # Author: xiaodongrush
5 #-----------------------------------------------------------#
6 use 5.010;
7 while (<>) {chomp; unshift @ array, $ _;}
8 foreach (@ array) {say $ _;}
9 <STDIN>
10 # @ _ indicates the parameter list of subprograms. $ _ is a common part of Perl and is easy to confuse.
Printf_example.pl
1 #-----------------------------------------------------------#
2 # Source: Learning Perl, chapter5, exercise-2
3 # Date: 2012-01-15
4 # Author: xiaodongrush
5 #-----------------------------------------------------------#
6 Use 5.010;
7 say "input several STR! (Use Control + Z to stop input ).";
8 while (<>) {chomp; push @ STRs, $ _;}
9 say "1234567890" x 4;
10 foreach (@ STRs) {printf "% 20s \ n", $ _;}
11 <stdin>
Printf_example_2.pl
1 #-----------------------------------------------------------#
2 # Source: Learning Perl, Chapter5, exercise-3
3 # Date: 2012-01-15
4 # Author: xiaodongrush
5 #-----------------------------------------------------------#
6 use 5.010;
7 say "Input several str! (Use Control + Z to Stop Input ).";
8 while (<>) {chomp; push @ strs, $ _;}
9 print "The Width of the Rule Line Width ="; $ width = <STDIN>;
10 print "1234567890" x ($ width/10 );
11 foreach (1 .. 9) {if ($ _ <= ($ width % 10) {print $ _ ;}} say;
12 foreach (@ strs) {printf "% 20s \ n", $ _;}
13 <STDIN>
3. File
/Files/pangxiaodong/learns ningperl/ch5-answer.rar