NAME

Data::AutoBimap - Bidirectional map for enumerated strings

SYNOPSIS

use Data::AutoBimap;
my $bm = Data::AutoBimap->new;
say $bm->s2n("Test"); # "1"
say $bm->s2n("123");  # "2"
say $bm->s2n("Test"); # "1"
say $bm->n2s(1);      # "Test"
$bm->n2s(3);          # undef

DESCRIPTION

This module maps scalars to automatically incrementing integer values and allows to perform reverse lookups of scalars by their associated integer value.

METHODS

new(%options)

Creates a new Data::AutoBimap object. The only valid option key is start providing the first value for the enumerator; defaults to 1.

s2n($scalar)

Returns the number associated with the scalar; if no number has been associated with the scalar previously, associates the next consecutive number with the scalar and returns it. The scalar will be used as key in a hash.

n2s($number)

Returns the scalar associated with the number or undef is no scalar is associated with it.

EXPORTS

None.

AUTHOR / COPYRIGHT / LICENSE

Copyright (c) 2014 Bjoern Hoehrmann <bjoern@hoehrmann.de>.
This module is licensed under the same terms as Perl itself.