![]() |
|
Don't ask to ask, just ask | |
PerlMonks |
Re: Basic question about Iterator codeby ikegami (Patriarch) |
on May 12, 2025 at 23:15 UTC ( [id://11165019]=note: print w/replies, xml ) | Need Help?? |
As a side note, if you want to support returning false values (such as zero, but particularly undef) easily, return an empty list when the iterator is exhausted.
or
Then, use a list assignment in scalar/boolean context.
You could have used while ( defined( my $i = $iter->() ). But you won't be able to use that for every iterators, such as one that returns the elements of an array:
Since you sometimes need to use the empty-list "trick", you might as well always use it for consistency. Also, it's shorter than using defined :)
In Section
Seekers of Perl Wisdom
|
|