#数据文件
%data = ();
dbmopen(%data,"data.dbm","0666") or warn("cannot link file $!\n");
$data{test2} = "test1";
$data{test3} = "test1";
$data{test4} = "test1";
$data{test5} = "test1";
$data{test6} = "test1";
$data{test7} = "test1";
$data{test9} = "test1";
dbmclose(%data);
#检索程序
# 备忘录
%hash = ();
dbmopen(%hash,"data.dbm","0666");
while(1)
{
print "enter \'quit\' can exit program:";
chomp($_=lc());
last if($_=~/^quit$/);
if($_=~/like\s+(.*)\?/)
{
$parten = $1;
while(($key,$value)=each(%hash))
{
if(grep(/\w*$parten\w*/,$key))
{
print "$key like $parten :value is $value\n";
}
}
}elsif(/(.*)\?/)
{
$parten = $1;
if($hash{$parten})
{
print "$parten value is $hash{$parten}"
}
}else{
print "I\'m sorry cannot find $_";
}
}
print "program has exited";
阅读(9744) | 评论(2) | 转发(0) |