in reply to Re: How to make references more like aliases?
in thread How to make references more like aliases?

blokhead,
I can certainly live with $group->[ <index> ] as it is much prettier. Thanks a bunch!
#!/usr/bin/perl use strict; use warnings; my @array = 0 .. 30; my $next = by_groups_of( 3, \@array ); while ( my $group = $next->() ) { $group->[1] = 'foo'; } print "$_\n" for @array; sub by_groups_of { my ($by, $list) = @_; return sub { () } if ! $by || $by =~ /\D/ || ! @$list; my $pos = 0; my $done; return sub { return () if $done || $pos > $#$list; my $start = $pos; my $stop = $pos + $by - 1 > $#$list ? $#$list : $pos + $by - 1 +; $pos += $by; $done = 1 if $stop == $#$list; return sub { \@_ }->( @$list[ $start .. $stop ] ); } }

Cheers - L~R

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