Data::Pairs

Perl module to implement ordered mappings with possibly duplicate keys
Download

Data::Pairs Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Brad Baxter
  • Publisher web site:
  • http://search.cpan.org/~bbaxter/

Data::Pairs Tags


Data::Pairs Description

Perl module to implement ordered mappings with possibly duplicate keys Data::Pairs is a Perl module that implements the Data::Pairs class. Objects in this class are ordered mappings, i.e., they are hashes in which the key/value pairs are in order. This is defined in shorthand as !!pairs in the YAML tag repository: http://yaml.org/type/pairs.html.The keys in Data::Pairs objects are not necessarily unique, unlike regular hashes.A closely related class, Data::Omap, implements the YAML !!omap data type, http://yaml.org/type/omap.html. Data::Omap objects are also ordered sequences of key/value pairs but they do not allow duplicate keys.While ordered mappings are in order, they are not necessarily in a particular order, i.e., they are not necessarily sorted in any way. They simply have a predictable set order (unlike regular hashes whose key/value pairs are in no set order).By default, Data::Pairs will add new key/value pairs at the end of the mapping, but you may request that they be merged in a particular order with the order() class method.However, even though Data::Pairs will honor the requested order, it will not attempt to keep the mapping in that order. By passing position values to the set() and add() methods, you may insert new pairs anywhere in the mapping and Data::Pairs will not complain.SYNOPSIS use Data::Pairs; # Simple OO style my $pairs = Data::Pairs->new( ); $pairs->set( a => 0 ); $pairs->add( b2 => 2.5, 2 ); # insert at position 2 (between b and c) my($value) = $pairs->get_values( 'c' ); # 3 (if you just want one) my @values = $pairs->get_values( 'b' ); # (2, 4) (one key, multiple values) my @keys = $pairs->get_keys(); # (a, b, b2, c, b) @values = $pairs->get_values(); # (0, 2, 2.5, 3, 4) my @subset = $pairs->get_values(qw(c b)); # (2, 3, 4) (values are data-ordered) # Tied style # Alas, because of duplicate keys, tying to a %hash is not supported. # Non-OO style use Data::Pairs ':ALL'; my $pairs = ; # new-ish, but not blessed pairs_set( $pairs, a => 0 ); # (pass pairs as first parameter) pairs_add( $pairs, b2 => 2.5, 2 ); # insert at position 2 (between b and c) my($value) = pairs_get_values( $pairs, 'c' ); # 3 (if you just want one) my @values = pairs_get_values( $pairs, 'b' ); # (2, 4) (one key, multiple values) my @keys = pairs_get_keys( $pairs ); # (a, b, b2, c, b) @values = pairs_get_values( $pairs ); # (0, 2, 2.5, 3, 4) my @subset = pairs_get_values( $pairs, qw(c b) ); # (2, 3, 4) (values are data-ordered) # There are more methods/options, see below. Requirements: · Perl


Data::Pairs Related Software