Update: I went off on a different problem. This is more to the point.

To batch through an array I'd collect indexes so there is no doubt but that I am dealing with the actual elements in the loop body.

Like:

my $i; my @ar = 0 .. 10; ($get_idx_grp, $fin_idx_grp) = mk_idx_funcs( 4, \$i, \@ar ); for ( $i = 0; $i < @ar; ++$i) { my @idx = &$get_idx_grp; $ar[ $idx[0] ] = "YYY"; &$fin_idx_grp; } sub mk_idx_funcs { # XXX bad name my ( $grp_size, $iter, $array ) = @_; my ( @group, $group_end ); my $first_call = 1; return ( sub { if ($first_call) { $first_call = 0; $group_end = $$iter + $grp_size; } if ( $$iter < $group_end and $$iter < @$array ) { push @group, $$iter; no warnings; next unless @group==$grp_size or $$iter==@$array-1; } return @group; }, sub { $group_end += @group; @group = (); return; } ); }
Original post follows

I would be interested in the aliasing most likely to avoid changing the identifiers in a loop body. Your code does not do this, so I do not understand what you are trying to achieve.

This seems simpler:

#!/usr/bin/perl use strict; use warnings; my @array = 0 .. 30; my $interval = make_interval(); for my $val ( @array ) { &$interval( 4); $val = "--"; }; local $, = " "; print @array, $/; sub make_interval { my $ctr = 0; my $start = 1; return sub { if ( $start) { $start = 0; return } $ctr++; if ( $ctr == $_[0]) { $ctr = 0 } else { no warnings; next } } }

In reply to Re: How to make references more like aliases? by rir
in thread How to make references more like aliases? by Limbic~Region

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.