in reply to Re: An iterator for (not "iterating") a recursive data structure.
in thread An iterator for (not "iterating") a recursive data structure.

>  while (defined( my $x = $it->() )) {

this whole defined thing to handle false values is IMHO flawed cargo cult, what if undef is a legal value of the data structure???

the easy solution is a list assignment denoted by parens

 while ( my ( $x ) = $it->() ) {

the loop will only terminate if the returned list is empty.

Hence problem solved with even shorter syntax.

(And returning multiple values becomes trivial, too)

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery