1 #!/usr/bin/perl -w
2
3 open(PH,"customers.txt") or die "laozi da bu kai !!! : $!\n";
4 while(
) {
5 chomp;
6 ($number,$email)=(split(/\s+/,$_))[1,2];
7 $Phone{$number}=$_;
8 $Email{$email}=$_;
9 }
10 close(PH);
11
12 print "Type 'q' to exit\n";
13 while(1) {
14 print "\nNumber? ";
15 $number=;chomp($number);
16 $address="";
17 if (! $number ) {
18 print "E-mail?";
19 $address=; chomp($address);
20 }
21
22 next if (! $number and ! $address);
23 last if ($number eq 'q' or $address eq 'q');
24
25 if ( $number and exists $Phone{$number} ) {
26 print "Customer: $Phone{$number}\n";
27 next;
28 }
29
30 if ($address and exists $Email{$address} ) {
31 print "Customer: $Email{$address}\n";
32 next;
33 }
34 print "Customer record not found.\n";
35 next;
36 }
37 print "\nAll done.\n";
阅读(1402) | 评论(0) | 转发(0) |