1Data::Stag::HashDB(3) User Contributed Perl DocumentationData::Stag::HashDB(3)
2
3
4
6 Data::Stag::HashDB - build indexes over Stag files or objects
7
9 # parsing a file into a hash
10 my $hdb = Data::Stag::HashDB->new;
11 $hdb->unique_key("ss_details/social_security_no");
12 $hdb->record_type("person");
13 my $obj = {};
14 $hdb->index_hash($obj);
15 Data::Stag->parse(-file=>$fn, -handler=>$hdb);
16 my $person = $obj->{'999-9999-9999'};
17 print $person->xml;
18
19 # indexing an existing stag tree into a hash
20 my $personset = Data::Stag->parse($fn);
21 my $hdb = Data::Stag::HashDB->new;
22 $hdb->unique_key("ss_details/social_security_no");
23 $hdb->record_type("person");
24 my $obj = {};
25 $hdb->index_hash($obj);
26 $personset->sax($hdb);
27 my $person = $obj->{'999-9999-9999'};
28 print $person->xml;
29
31 Used for building indexes over Stag files or objects
32
33 You need to provide a record_type - this is the type of element that
34 will be indexed
35
36 You need to provide a unique_key - this is a single value used to index
37 the record_types
38
39 For example, if we have data in the stag structure below, and if ss_no
40 is unique (we assume it is) then we can index all the people in the
41 database using the code above
42
43 publicinfo:
44 persondata:
45 person:
46 ss_details:
47 social_security_no:
48 name:
49 address:
50
51 There is a subclass of this method callsed Data::Stag::StagDB, which
52 makes the hash persistent
53
55 record_type
56 Usage -
57 Returns -
58 Args -
59
60 unique_key
61 Usage -
62 Returns -
63 Args -
64
65 index_hash
66 Usage -
67 Returns -
68 Args -
69
71 Hey! The above document had some coding errors, which are explained
72 below:
73
74 Around line 40:
75 Deleting unknown formatting code N<>
76
77
78
79perl v5.34.0 2021-07-22 Data::Stag::HashDB(3)