NAME
Data::Iter - easily iterate over a hash/array
SYNOPSIS
use Data::Iter qw(:all);
my @days = qw/Mon Tue Wnd Thr Fr Su So/;
foreach ( iter \@days )
{
printf "Day: %s [%s]\n", VALUE, counter;
}
foreach my $i ( iter \@days )
{
printf "Day: %s [%s]\n", $i->VALUE, $i->counter;
}
my %numbers = ( 1 => 'one', 2 => 'two', 3 => 'three', 4 => 'four' );
foreach ( iter \%numbers )
{
printf "%10s [%10s] %10d\n", key, value, counter;
}
foreach my $i ( iter \%numbers )
{
printf "%10s [%10s] %10d\n", $i->key, $i->value, $i->counter;
}
foreach ( iter \%numbers )
{
printf "%10s [%10s] %10d\n", KEY, VALUE, COUNTER;
}
DESCRIPTION
Data::Iter provides functions for comfortably iterating over perl data structures.
iter
Accepts a reference to an ARRAY or HASH. Returns a sorted list of 'Data::Iter' objects.
key() or KEY()
Returns the current key (HASHs only).
value() or VALUE()
Returns the current value.
counter()
Returns the current counter (starting at 0).
getvalue( index )
Returns the value at index. It behaves like an array index.
get( index )
Returns the Data::Iter object at index. It behaves like an array index.
CAVE: Future variables are read-only ! It is the common "foreach( @something ) not change during iteration through it" story.
Example:
get(-1) will return the last iterator object.
get(-1)->value will return the position of the last
get(-1)->value will return the value of the last
get(1+counter) will return the next object
BUGS
Not get(counter+1), but get(1+counter) will function correctly (under perl 5.6.0).
And get(counter - 1) does not work.
EXPORT
none by default.
all: iter counter counter value VALUE key KEY get
AUTHOR
M. Ünalan, <muenalan@cpan.org>
SEE ALSO
Class::Iter, Tie::Array::Iterable, Object::Data::Iterate
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 223:
Non-ASCII character seen before =encoding in 'Ünalan,'. Assuming CP1252