in reply to Re: Return a list or an iterator
in thread Return a list or an iterator

The safe way to handle undefs as a valid element is to have the iterator return one element in list context and an empty list if there's no elements, and then always call it in list context when iterating over it.
my $iter = sub { @foo ? shift @foo : () }; while (my ($elem) = $iter->()) { # $elem may be undefined. }
This way you don't need it to be an object and you don't need any special end-of-list elements.