37 print "
----------------------------------_exercise_6_1--------------------------
";
38 my %bless_function = ( #hash may be a lexical variable
39 "constructors" => "default_values",
40 "error_handling" => undef,
41 "existence_test_for" => "fat_commas",
42 "grep_func" => "labeled",
43 );
44 my $unpackeing;
45 my $arrow_notation = '';
46 print "Enter name to query, enter exit to exit:
";
47 $arrow_notation = ( chomp( $unpackeing = <STDIN>) );
48 while ($unpackeing ne "exit") {
49 print "Qurery result: ".$bless_function{$unpackeing}."
";
50 print "Enter name to query, enter "exit" to exit:
";
51 chomp( $unpackeing = <STDIN>);
52 print "
";
53 }
54 =head1
55 $arrow_notation = "exit";
56 while($arrow_notation ne "exit"){
57 print "while loop.
";
58 }
59 =cut
60 print "
----------------------------------_exercise_6_1--------------------------
";
输出:
----------------------------------_exercise_6_1--------------------------
Enter name to query, enter exit to exit:
grep_func
1 grep_func
next line is while.
Qurery result: labeled
Enter name to query, enter exit to exit:
^C
第六章后半段练习代码:
bash-2.03$ vim hash_exists_del_func_exercise.pl
1 #! /usr/bin/perl
2 use strict;
3 use warnings;
4
5 print "
----------------------------------exists_hash_func_--------------------------
";
6 my %vertical_alignment;
7 $vertical_alignment{"subscripting"} = 0;
8 unless($vertical_alignment{"array_ref"}){
9 print "0
";
10 }
11 printf keys %vertical_alignment;
12 if( exists $vertical_alignment{"array_ref"}){
13 print "
there is a library card for subscripting
";
14 }
15 else{
16 print "
no card.
";
17 }
18 $vertical_alignment{"array_ref"} = undef;
19 $vertical_alignment{"attr_demolition"} = "indices";
20 printf keys %vertical_alignment;
21 if( exists $vertical_alignment{"array_ref"}){
22 print "
there is a library card for subscripting
";
23 }
24 else{
25 print "
no card.
";
26 }
27 print "
----------------------------------exists_hash_func_--------------------------
";
28
29 print "
----------------------------------delete_hash_func_--------------------------
";
30 my $anonymous = "subscripting";
31 print $vertical_alignment{$anonymous}."
";
32 delete $vertical_alignment{$anonymous};
33 my @refer_to = keys %vertical_alignment;
34 print "@refer_to";
35 print "
----------------------------------delete_hash_func_--------------------------
";
36
37 print "
----------------------------------_exercise_6_1--------------------------
";
38 my %bless_function = ( #hash may be a lexical variable
39 "constructors" => "default_values",
40 "error_handling" => undef,
41 "existence_test_for" => "fat_commas",
42 "grep_func" => "labeled",
43 );
44 my $unpackeing;
45 my $arrow_notation = '';
46 print "Enter name to query, enter exit to exit:
";
47 $arrow_notation = ( chomp( $unpackeing = <STDIN>) );
48 while ($unpackeing ne "exit") {
49 print "Qurery result: ".$bless_function{$unpackeing}."
";
50 print "Enter name to query, enter "exit" to exit:
";
51 chomp( $unpackeing = <STDIN>);
52 print "
";
53 }
54 =head1
55 $arrow_notation = "exit";
56 while($arrow_notation ne "exit"){
57 print "while loop.
";
58 }
59 =cut
60 print "
----------------------------------_exercise_6_1--------------------------
";