jfroebe has asked for the wisdom of the Perl Monks concerning the following question:

I've been reading Mark Jason Dominus's excellent Higher Order Perl during my wife's weekly Stitch & Bitch meeting. In the pursuit to get going on using Iterators, I started looking through CPAN and Perlmonks for a ready made Iterator class that would be a superclass for many other iterator classes. Guess what I found.. a hodge podge of iterators that seem mostly to be almost entirely independent implementations of what an iterator is/does. At least, that is the impression that is getting across.

Yup, I'm aware of Iterator, Iterator::Misc, and Iterator::Util but they don't seem to be used in the other cpan modules very much.

Has anyone else seen this or am I just suffering from "Friday: brain shuts down"?

Jason L. Froebe

Help find a cure for breast cancer! Net proceeds benefit the Susan G. Komen Breast Cancer Foundation and the National Philanthropic Trust. Help by donating - I'm walking 60 miles in 3 days in August 2007. (The day I return from TechWave is the first day of the Walk).

Blog, Tech Blog

Replies are listed 'Best First'.
Re: A standard Iterator super class?
by ambrus (Abbot) on Mar 23, 2007 at 19:44 UTC

    Ruby has a general iterator superclass (mixin really) in its core, called Enumerable. It contains methods such as map, grep, sort etc. The only method required from the including class is each which iterates over all elements, calling the block for every element (though the Array class overrides some methods for efficency). There are also some libraries providing extra methods to this class.

Re: A standard Iterator super class?
by dmitri (Priest) on Mar 23, 2007 at 16:15 UTC
    I never had a need to use an iterator class, though I use iterators often. I just roll my own.

    I, too, would be interested to learn the advantages of iterator classes versus simple home-grown closures.

Stitch & Bitch
by dmitri (Priest) on Mar 23, 2007 at 16:10 UTC
    You have me intrigued -- what's a "Stitch & Bitch meeting?"
      "Stitch & Bitch" = A knitting or sewing club.