I have seen several modules (example: Iterator::Simple) that make use of Perl’s angle operator as an approximate equivalent to Python generators. Specifically, providing the ability to iterate over a list of values without actually loading the whole list in memory. Is this generally considered to be an appropriate extension of the functionality of the operator, or is it considered to be an abuse of it?
I have seen several modules (example: Iterator::Simple ) that make use of Perl’s angle
Share
The
<HANDLE>operator is just syntactic sugar for thereadline HANDLEfunction, which is very much an iterator over the handle. If an object provides iterative access, I don’t see any problem with overloading<>to provide flexibility to the end user.The
<>operator does not approximate the generator, the module does that. All thatgives you is a fancy way to write
Perl is a very expressive language due to the many different ways it allows you to solve problems. Many modules choose to offer alternative interfaces in this spirit. This allows users to code the way that works best for them.