Hash::Iterator - Hashtable Iterator.
my $iterator = Hash::Iterator->new( map { $_ => uc $_ } 'a'..'z' ); while ($iterator->next) { say sprintf("%s => %s", $iterator->peek_key, $iterator->peek_value); } my $iterator = Hash::Iterator->new( a => [qw(one two three)] ); $iterator->next; if ( $iterator->is_ref('ARRAY') ) { foreach my $item ( @{$iterator->peek_value} ) { say $item; } }
my $iterator = Hash::Iterator->new( %hash );
Return a Hash::Iterator for hash
hash
$iterator->next;
Advance the iterator to the next key-value pair
$iterator->previous;
Advance the iterator to the previous key-value pair
do { .... } while ($iterator->done);
Returns a boolean value if the iterator was exhausted
say $iterator->peek_key;
Return the key of the current key-value pair. It's not allowed to call this method before next() was called for the first time or after the iterator was exhausted.
say $iterator->peek_value;
Return the value of the current key-value pair. It's not allowed to call this method before next() was called for the first time or after the iterator was exhausted.
if ( $iterator->is_ref('ARRAY') ) { ... }
Returns a boolean value if value is a reference.
my @keys = $iterator->get_keys;
Returns a list of all keys from hash
vlad mirkos, <vladmirkos@sd.apple.com>
Copyright (C) 2017 by vlad mirkos
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.18.2 or, at your option, any later version of Perl 5 you may have available.
To install Hash::Iterator, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Hash::Iterator
CPAN shell
perl -MCPAN -e shell install Hash::Iterator
For more information on module installation, please visit the detailed CPAN module installation guide.