---
name: "Dpkg::Index"
section: "3perl"
platform: "linux"
package: "dpkg"
version: "1.23.11-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/Dpkg::Index/3perl"
---

# Dpkg::Index(3perl)

generic index of control information

## NAME

Dpkg::Index - generic index of control information

## DESCRIPTION

This class represent a set of Dpkg::Control objects.

## METHODS

- $index = Dpkg::Index-\>new(%opts)

  Creates a new empty index. See **set\_options()** for more details.

- $index-\>set\_options(%opts)

  Change the value of some options.

  Options:

  - **type**

    Set the deb822 control type, used to setup default values for other options.

  - **item\_opts**

    Set a hash reference that will be passed to the item constructor in the `$index`-\>**new\_item()** method. The index can only contain one item with a given key.

  - **unique\_tuple\_key**

    Set a boolean requesting whether the default key should be the unique tuple (default to true).

  - **get\_key\_func**

    Set a function returning a key for the item passed in parameters.

    The default depends on the type:

    - •

      for CTRL\_TMPL\_SRC, it is the Source field;

    - •

      for CTRL\_REPO\_SRC and CTRL\_DSC it is the Package and Version fields (concatenated with "\_") when **unique\_tuple\_key** is true (the default), or otherwise the Package field;

    - •

      for CTRL\_TMPL\_PKG it is the Package field;

    - •

      for CTRL\_REPO\_PKG and CTRL\_DEB it is the Package, Version and Architecture fields (concatenated with "\_") when **unique\_tuple\_key** is true (the default) or otherwise the Package field;

    - •

      for CTRL\_CHANGELOG it is the Source and the Version fields (concatenated with an intermediary "\_");

    - •

      for CTRL\_TESTS is an integer index (0-based) corresponding to the Tests or Test-Command field stanza;

    - •

      for CTRL\_FILE\_CHANGES it is the Source, Version and Architecture fields (concatenated with "\_");

    - •

      for CTRL\_FILE\_VENDOR it is the Vendor field;

    - •

      for CTRL\_FILE\_STATUS it is the Package and Architecture fields (concatenated with "\_");

    - •

      otherwise it is the Package field by default.

- $type = $index-\>**get\_type()**

  Returns the type of control information stored. See the type parameter set during **new()**.

- $index-\>add($item, \[$key\])

  Add a new item in the index. If the `$key` parameter is omitted, the key will be generated with the get\_key\_func function (see **set\_options()** for details).

- $count = $index-\>parse($fh, $desc)

  Reads the filehandle and creates all items parsed. When called multiple times, the parsed stanzas are accumulated.

  Returns the number of items parsed.

- $count = $index-\>load($file)

  Reads the file and creates all items parsed. Returns the number of items parsed. Handles compressed files transparently based on their extensions.

- $item = $index-\>**new\_item()**

  Creates a new item. Mainly useful for derived objects that would want to override this method to return something else than a Dpkg::Control object.

- $item = $index-\>get\_by\_key($key)

  Returns the item identified by `$key` or undef.

- @keys = $index-\>get\_keys(%criteria)

  Returns the keys of items that matches all the criteria. The key of the `%criteria` hash is a field name and the value is either a regex that needs to match the field value, or a reference to a function that must return true and that receives the field value as single parameter, or a scalar that must be equal to the field value.

- @items = $index-\>get(%criteria)

  Returns all the items that matches all the criteria.

- $item = $index-\>remove\_by\_key($key)

  Remove the item identified by the given key.

  Returns the removed item.

- @items = $index-\>remove(%criteria)

  Returns and removes all the items that matches all the criteria.

- $index-\>merge($other\_index, %opts)

  Merge the entries of the other index. While merging, the keys of the merged index are used, they are not re-computed. It's your responsibility to ensure that they have been computed with the same function.

  Options:

  - **keep\_keys**

    Set whether to re-compute the keys from the other index. Defaults to 1.

- $index-\>sort(\\&sortfunc)

  Sort the index with the given sort function. If no function is given, an alphabetic sort is done based on the keys. The sort function receives the items themselves as parameters and not the keys.

- $string = "$index"

  - $string = $index-\>output(\[$fh\])

  Get a string representation of the index. The Dpkg::Control objects are output in the order which they have been read or added except if the order have been changed with **sort()**.

  Print the string representation of the index to a filehandle if `$fh` has been passed.

- $index-\>save($file)

  Writes the content of the index in a file. Auto-compresses files based on their extensions.

## CHANGES

### Version 3.00 (dpkg 1.21.2)

Change behavior: The CTRL\_TESTS key now defaults to a stanza index.

### Version 2.01 (dpkg 1.20.6)

New option: Add new "item\_opts" option.

### Version 2.00 (dpkg 1.20.0)

Change behavior: The "unique\_tuple\_key" option now defaults to true.

### Version 1.01 (dpkg 1.19.0)

New option: Add new "unique\_tuple\_key" option to `$index`-\>**set\_options()** to set better default "get\_key\_func" options, which will become the default behavior in 1.20.x.

### Version 1.00 (dpkg 1.15.6)

Mark the module as public.
