Array::OrdHashOrdered associative array with array-like, hash-like and OO interface | |
Download |
Array::OrdHash Ranking & Summary
Advertisement
- License:
- Perl Artistic License
- Price:
- FREE
- Publisher Name:
- Vladimir Surin
- Publisher web site:
- http://search.cpan.org/~wowasurin/
Array::OrdHash Tags
Array::OrdHash Description
Ordered associative array with array-like, hash-like and OO interface Array::OrdHash is a Perl module that implements Perl arrays that have both numeric and string indices, similar to PHP arrays or Collections, therefore the array keys are unique strings.The order in which the elements were added is preserved just like Tie::IxHash does this.Both Perl array and Perl hash functions can be performed on a variable of this class. The elements of an array may be sorted both by keys and values, or with an external callback subroutine. They can also be reordered.SYNOPSIS use Array::OrdHash; $oh = Array::OrdHash->new; $oh->{'a'} = 'First'; $oh->{'b'} = 'Second'; $oh->{'c'} = 'Third'; $oh-> = 'new First'; $oh-> = 'new Second'; $oh-> = 'Forth'; # (would be croaked) exists $oh->{'c'}; exists $oh->; # the same result delete $oh->{'c'}; delete $oh->; # the same result # inserting a list @LIST = ('d'=>'Forth', 'e'=>'Fifth', 'f'=>'Sixth'); push @$oh, @LIST; unshift @$oh, ('i'=>'I', 'j'=>'J', 'k'=>'K'); # iterating as a hash while (($key, $val) = each %$oh) { print "$key=", $val, "\n"; } # iterating as a list (more efficient) while (($key, $val, $ind) = $oh->List) { print "($ind) $key = $val\n"; } # iterating as an array foreach $val (@$oh) { print $val, "\n"; } $oh->Reset(); # pop, shift and splice $item = pop @$oh; $item = shift @$oh; @spliced = splice @$oh, $offset, $len ; # keys and values arrays @k = keys %$oh; @v = values %$oh; @k = $oh->Keys(); @v = $oh->Values(); # miscellaneous $oh->Sort( src=>'keys' ); $oh->Sort( src=>'values DESC' ); $oh->Sort( proc=>\&SortProcedure ); $oh->Reorder(LIST); $oh->First(); $oh->Last() $oh->Indices(LIST); $oh->Length(); Requirements: · Perl
Array::OrdHash Related Software