Softpedia
 


LINUX CATEGORIES:



GLOBAL PAGES >>
NEWS ARCHIVE >>
SOFTPEDIA REVIEWS >>
MEET THE EDITORS >>
WEEK'S BEST
  • Linux Kernel 3.9.3 / 3....
  • LibreOffice 3.6.6 / 4.0.3
  • MPlayer 1.1.1
  • systemd 204
  • Arch Linux 2013.05.01
  • Blender 2.67
  • KDE Software Compilatio...
  • CrunchBang Linux Stable...
  • Elementary OS 0.1 / 0.2...
  • SystemRescueCd 3.6.0
  • Home > Linux > Programming > Libraries

    Tie::Hash::MultiValue 0.05

    Download button

    No screenshots available
    Downloads: 335  View global page NEW!  Tell us about an update
    User Rating:
    Rated by:
    NOT RATED
    0 user(s)
    Developer:

    License / Price:

    Last Updated:

    Category:
    Joe McMahon | More programs
    Perl Artistic License / FREE
    October 10th, 2007, 05:05 GMT
    ROOT / Programming / Libraries

     Read user reviews (0)  Refer to a friend  Subscribe

    Tie::Hash::MultiValue description

    Tie::Hash::MultiValue is a Perl module that can store multiple values per key.

    Tie::Hash::MultiValue is a Perl module that can store multiple values per key.

    SYNOPSIS

    use Tie::Hash::MultiValue;
    tie %hash, 'Tie::Hash::Multivalue';
    $hash{'foo'} = 'one';
    $hash{'bar'} = 'two';
    $hash{'bar'} = 'three';

    my @values = @{$hash{'foo'}}; # @values = ('one');
    my @more = @{$hash{'bar'}}; # @more = ('two', 'three');
    my @nothing = $hash{'baz'}; # undefined if nothing there

    # You can save multiple values:
    map { $hash{'more'} = $_ } qw(fee fie foe fum);
    my @giant_words = @{$hash{'more'}};

    # You can tie an anonymous hash as well.
    my $hash = {};
    tie %$hash, 'Tie::Hash::MultiValue';
    $hash->{'sample'} = 'one';
    $hash->{'sample'} = 'two';
    # $hash->{'sample'} now contains ['one','two']

    Tie::Hash::Multivalue allows you to have hashes which store their values in anonymous arrays, appending any new value to the already-existing ones.

    This means that you can store as many items as you like under a single key, and access them all at once by accessing the value stored under the key.

    METHODS

    This class is a subclass of Tie::ExtraHash; it needs to override the TIEHASH method to save the instance data (in $self->[1]), and the STORE method to actually save the values in an anonymous array.

    TIEHASH

    If the 'unique' argument is supplied, we check to see if it supplies a subroutine reference to be used to compare items. If it does, we store that reference in the object describing this tie; if not, we supply a function which simply uses 'eq' to test for equality.

    The 'unique' function

    This funtion will receive two scalar arguments. No assumption is made about whether or not either argument is defined, nor whether these are simple scalars or references. You can make any of these assumptions if you choose, but you are responsible for checking your input.

    You can perform whatever tests you like in your routine; you should return a true value if the arguments are determined to be equal, and a false one if they are not.

    STORE

    Push the value(s) supplied onto the list of values stored here. The anonymous array is created automatically if it doesn't yet exist.

    If the 'unique' argument was supplied at the time the hash was tied, we will use the associated function (either yours, if you supplied one; or ours, if you didn't) and only add the item or items that are not present.

    Product's homepage

    Requirements:

    · Perl

      


    TAGS:

    hash-based storage | multiple values | Perl module | hash | values | storage

    Go to top

    WindowsGamesDriversMacLinuxScriptsMobileHandheldNews

    SUBMIT PROGRAM   |   ADVERTISE   |   GET HELP   |   SEND US FEEDBACK   |   RSS FEEDS   |   UPDATE YOUR SOFTWARE   |   ROMANIAN FORUM