Martin H. Sluka > Tie-Hash-Array-0.1 > Tie::Hash::Abbrev

Download:
Tie-Hash-Array-0.1.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.1   Source  

NAME ^

Tie::Hash::Abbrev - a hash which can be accessed using abbreviated keys

SYNOPSIS ^

  use Tie::Hash::Abbrev;

  tie my %hash, 'Tie::Hash::Abbrev';

  %hash = ( sonntag   =>0, montag =>1, dienstag=>2, mittwoch =>3,
            donnerstag=>4, freitag=>5, samstag =>6,
            sunday    =>0, monday =>1, tuesday =>2, wednesday=>3,
            thursday  =>4, friday =>5, saturday=>6 );

  print $hash{do}; # will print "4"
  print $hash{fr}; # undef
  print $hash{t};  # undef

  my @deleted = tied(%hash)->delete_abbrev( qw{do fr t} );
    # will delete element "donnerstag"; @deleted will be (4)

DESCRIPTION ^

This module implements a subclass of Tie::Hash::Array. The contents of hashes tied to this class may be accessed via unambiguously abbreviated keys. (Please note, however, that this is not true for deleting hash elements; for that, can use "delete_abbrev()" via the object interface.)

While you could achieve a similar behaviour by using the standard module Text::Abbrev for mapping abbreviations to the original keys, the (main) advantage of Tie::Hash::Abbrev is that you do not have to calculate all possible abbreviations in advance each time a key is altered, and you do not have to store them in memory.

ADDITIONAL METHODS ^

delete_abbrev

  my @deleted = tied(%hash)->delete_abbrev('foo','bar');

Will delete all elements on the basis of all unambiguous (in the sense of this module or the subclass used) abbreviations given as arguments and return a (possibly empty) list of all deleted values.

SUBCLASSING ^

Please do not rely on the implementation details of this class for now, since they may still be subject to change.

If you'd like to subclass this module, please let me know; perhaps we can agree on some standards then.

BUGS ^

None known so far.

AUTHOR ^

        Martin H. Sluka
        mailto:perl@sluka.de
        http://martin.sluka.de/

COPYRIGHT & LICENCE ^

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

The full text of the license can be found in the LICENSE file included with this module.

SEE ALSO ^

Tie::Hash::Array, Tie::Hash::Abbrev::Smart

syntax highlighting: