---
name: "Data::Stag::HashDB"
section: "3pm"
platform: "linux"
package: "libdata-stag-perl"
version: "0.14-3"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/Data::Stag::HashDB"
---

# Data::Stag::HashDB(3pm)

## NAME

```
  Data::Stag::HashDB - build indexes over Stag files or objects
```

## SYNOPSIS

```
  # parsing a file into a hash
  my $hdb = Data::Stag::HashDB->new;
  $hdb->unique_key("ss_details/social_security_no");
  $hdb->record_type("person");
  my $obj = {};
  $hdb->index_hash($obj);
  Data::Stag->parse(-file=>$fn, -handler=>$hdb);
  my $person = $obj->{'999-9999-9999'};
  print $person->xml;
  # indexing an existing stag tree into a hash
  my $personset = Data::Stag->parse($fn);
  my $hdb = Data::Stag::HashDB->new;
  $hdb->unique_key("ss_details/social_security_no");
  $hdb->record_type("person");
  my $obj = {};
  $hdb->index_hash($obj);
  $personset->sax($hdb);
  my $person = $obj->{'999-9999-9999'};
  print $person->xml;
```

## DESCRIPTION

Used for building indexes over Stag files or objects

You need to provide a **record\_type** - this is the type of element that will be indexed

You need to provide a **unique\_key** - this is a single value used to index the **record\_type**s

For example, if we have data in the stag structure below, and if ss\_no is unique (we assume it is) then we can index all the people in the database using the code above

```
  publicinfo:
    persondata:
      person:
        ss_details:
          social_security_no:
        name:
        address:
```

There is a subclass of this method callsed Data::Stag::StagDB, which makes the hash persistent

## PUBLIC METHODS -

### record\_type

```
  Usage   -
  Returns -
  Args    -
```

### unique\_key

```
  Usage   -
  Returns -
  Args    -
```

### index\_hash

```
  Usage   -
  Returns -
  Args    -
```
