码迷,mamicode.com
首页 > 编程语言 > 详细

Perl语言入门:第六章习题:处理用户所指定的名字并汇报相应的姓。

时间:2019-06-17 10:49:47      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:for   cut   scripting   erro   func   vim   bin   ror   card   

 

37 print "\n----------------------------------_exercise_6_1--------------------------\n";
     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:\n";
     47 $arrow_notation = ( chomp( $unpackeing = <STDIN>) );
     48 while ($unpackeing ne "exit") {
     49     print "Qurery result: ".$bless_function{$unpackeing}."\n";
     50     print "Enter  name to query, enter "exit" to exit:\n";
     51     chomp( $unpackeing = <STDIN>);
     52     print "\n";
     53 }
     54 =head1
     55 $arrow_notation = "exit";
     56 while($arrow_notation ne "exit"){
     57     print "while loop.\n";
     58 }
     59 =cut
     60 print "\n----------------------------------_exercise_6_1--------------------------\n";

 

输出:

----------------------------------_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 "\n----------------------------------exists_hash_func_--------------------------\n";
      6 my %vertical_alignment;
      7 $vertical_alignment{"subscripting"} = 0;
      8 unless($vertical_alignment{"array_ref"}){
      9     print "0\n";
     10 }
     11 printf keys %vertical_alignment;
     12 if( exists $vertical_alignment{"array_ref"}){
     13     print "\nthere is a library card for subscripting\n";
     14 }
     15 else{
     16     print "\nno card.\n";
     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 "\nthere is a library card for subscripting\n";
     23 }
     24 else{
     25     print "\nno card.\n";
     26 }
     27 print "\n----------------------------------exists_hash_func_--------------------------\n";
     28
     29 print "\n----------------------------------delete_hash_func_--------------------------\n";
     30 my $anonymous = "subscripting";
     31 print $vertical_alignment{$anonymous}."\n";
     32 delete $vertical_alignment{$anonymous};
     33 my @refer_to = keys %vertical_alignment;
     34 print "@refer_to";
     35 print "\n----------------------------------delete_hash_func_--------------------------\n";
     36
     37 print "\n----------------------------------_exercise_6_1--------------------------\n";
     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:\n";
     47 $arrow_notation = ( chomp( $unpackeing = <STDIN>) );
     48 while ($unpackeing ne "exit") {
     49     print "Qurery result: ".$bless_function{$unpackeing}."\n";
     50     print "Enter  name to query, enter "exit" to exit:\n";
     51     chomp( $unpackeing = <STDIN>);
     52     print "\n";
     53 }
     54 =head1
     55 $arrow_notation = "exit";
     56 while($arrow_notation ne "exit"){
     57     print "while loop.\n";
     58 }
     59 =cut
     60 print "\n----------------------------------_exercise_6_1--------------------------\n";

Perl语言入门:第六章习题:处理用户所指定的名字并汇报相应的姓。

标签:for   cut   scripting   erro   func   vim   bin   ror   card   

原文地址:https://www.cnblogs.com/books2read/p/11038261.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!