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).
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.