"Sputnik" help  
Sputnik Help
Language Reference - Classes - Class Magic Functions - IteratorValid

Class Magic Functions - IteratorValid

This allows a class to become an iterator and produce keys/values as and when requested for example:

class testy
{
    my $v = array("cat", "dog", "fox");
    my $p = 0;
    Function __IteratorValid()
    {
        return $p < ^^$v;
    }
    Function __IteratorKey()
    {
        return null;
    }
    Function __IteratorNext()
    {
        return $v[$p++];
    }
    Function __IteratorRewind()
    {
        $p = 0;
    }
}
$a = new testy();
say Implode(",", $a); 
// PRINTS
// cat,dog,fox

A full list of all possible magic functions can be found here.


Contact
Cheryl (uberfox@hotmail.com)
Homepage
http://ubersoft.org