in reply to How to make references more like aliases?

When you return a list and assign it to an array, the list elements are copied across the assignment operator. So any solution involving:
while ( my @group = $next->() )
is not going to preserve aliasing. @group is going to get copies of whatever was used in the return statement of the iterator.

Instead, you'll have to return an array reference. As for getting the aliases, the only way to get aliases is through argument passing. An idiomatic way is with:

my $arrayref_of_aliases = sub { \@_ }->( $stuff, $to, $alias );
In terms of your code, you change the return line of the iterator to:
return sub { \@_ }->( @$list[ $start .. $stop ] );
Then it works as you'd expect (with the appropriate changes in the calling code's while loop).

blokhead

Replies are listed 'Best First'.
Re^2: How to make references more like aliases?
by Limbic~Region (Chancellor) on Sep 28, 2004 at 00:52 UTC
    blokhead,
    I can certainly live with $group->[ <index> ] as it is much prettier. Thanks a bunch!

    Cheers - L~R

    Update: Modified code here to reflect all the recommendations and bug fixes