- #删除条目
- #!/bin/perl
- use AnyDBM_File;
- dbmopen(%states, "statedb", 0666) || die;
- TRY: {
- print "state abbreviation to remove. ";
- chomp($abbrev=<STDIN>);
- $abbrev = uc $abbrev;
- delete $states{"$abbrev"};
- print "$abbrev removed.\\n";
- print "Another entry? ";
- $answer = <STDIN>;
- redo TRY if $answer =~ /Y|y/;
- }
- dbmclose(%states);
- #数据查询
- #!/bin/perl
- use AnyDBM_File;
- dbmopen(%states, "statedb", 0666);
- @sortedkeys=sort keys %states;
- foreach $key ( @sortedkeys ){
- $value=$states{$key};
- $total++;
- write;
- }
- dbmclose(%states);
- format STDOUT_TOP=
- Abbreviation State
- ------------------------------
- .
- format STDOUT=
- @<<<<<<<<<<<<<<@<<<<<<<<<<<<<<<
- $key, $value
- .
- format SUMMARY=
- ------------------------------
- Number of states:@###
- $total
- .
- $~=SUMMARY;
- write;
- #读写操作
- #!/usr/bin/perl
- use AnyDBM_File;
- dbmopen(%states, "statedb", 0666[a]) || die;
- TRY: {
- print "State Abbreviation:";
- chomp($abbrev=<STDIN>);
- $abbrev = uc $abbrev;
- print "Name of the state:";
- chomp($state=<STDIN>);
- lc $state;
- $states{$abbrev}="\\u$state";
- print "Another entry? ";
- $answer = <STDIN>;
- redo TRY if $answer =~ /Y|y/;
- }
- dbmclose(%states);
- #该片段来自于http://www.codesnippet.cn/detail/090920135730.html
来源: http://www.codesnippet.cn/detail/090920135730.html