1 |
dpavlin |
30 |
#!/usr/bin/perl |
2 |
|
|
|
3 |
|
|
use warnings; |
4 |
|
|
use strict; |
5 |
|
|
|
6 |
|
|
use blib; |
7 |
|
|
use Search::TokyoDystopia; |
8 |
|
|
|
9 |
|
|
=head1 NAME |
10 |
|
|
|
11 |
|
|
tcidb.pl - example from documentation translated to perl |
12 |
|
|
|
13 |
|
|
=cut |
14 |
|
|
|
15 |
|
|
# create the object |
16 |
|
|
my $idb = tcidbnew(); |
17 |
|
|
|
18 |
|
|
# open the database |
19 |
dpavlin |
36 |
if (!tcidbopen($idb, "casket-idb", IDBOWRITER | IDBOCREAT)) { |
20 |
dpavlin |
30 |
my $ecode = tcidbecode($idb); |
21 |
|
|
die "open error: ", tcidberrmsg($ecode); |
22 |
|
|
} |
23 |
|
|
|
24 |
|
|
# store records |
25 |
|
|
if( |
26 |
|
|
!tcidbput($idb, 1, "George Washington") || |
27 |
|
|
!tcidbput($idb, 2, "John Adams") || |
28 |
|
|
!tcidbput($idb, 3, "Thomas Jefferson") |
29 |
|
|
){ |
30 |
|
|
my $ecode = tcidbecode($idb); |
31 |
|
|
die("put error: ", tcidberrmsg($ecode)); |
32 |
|
|
} |
33 |
|
|
|
34 |
|
|
# search records |
35 |
|
|
my $result = tcidbsearch2($idb, "john || thomas"); |
36 |
|
|
if($result){ |
37 |
|
|
foreach my $i ( @$result ) { |
38 |
|
|
my $text = tcidbget($idb, $i); |
39 |
|
|
printf("%d\t%s\n", $i, $text); |
40 |
|
|
} |
41 |
|
|
} else { |
42 |
|
|
my $ecode = tcidbecode($idb); |
43 |
|
|
die("search error: ", tcidberrmsg($ecode)); |
44 |
|
|
} |
45 |
|
|
|
46 |
|
|
# close the database |
47 |
|
|
if(!tcidbclose($idb)){ |
48 |
|
|
my $ecode = tcidbecode($idb); |
49 |
|
|
die("close error: ", tcidberrmsg($ecode)); |
50 |
|
|
} |
51 |
|
|
|
52 |
|
|
# delete the object |
53 |
|
|
tcidbdel($idb); |
54 |
|
|
|