http://www.perlmonks.org?node_id=440107


in reply to Re: Array iterator factory
in thread Array iterator factory

If I took a list, I'd have to make and store a copy of its contents. It would be expensive, and it would not see subsequent changes to the original array. I wanted a lightweight iterator tied to a user-modifiable array.

The user can create an anonymous array and slap an iterator on it, if he so desires: array_iterator(@{[1..10]}). That makes it obvious that this iterator can't give you the free lunch that for (1..10) does.


Caution: Contents may have been coded under pressure.

Replies are listed 'Best First'.
Re^3: Array iterator factory (&)
by tye (Sage) on Mar 17, 2005 at 03:25 UTC

    Don't forget the power of &array_iterator([1..10]).

    - tye        

        Ah, it's related to ihb's post.

        No, not directly. ihb's post is about avoiding using ampersand without parens to call subroutines except for "advanced purposes" (if you don't know what those are, then you shouldn't be doing them). Using ampersand with parens is great for bypassing prototypes and/or for ensuring you call a user-defined function even if there might be a built-in function by the same name.

        - tye