The point about the advantages of
local *_ = \ $array[$i]; is well taken, but I absolutely hate
for(;;) loops. It seems like I've made a fencepost error almost every time I wrote one of those. There are
very few cases where it's the most appropriate solution. Since
for(;;) is implemented in terms of
while(){} continue{}, you should use
while(){} unless you actually need a very simple
continue{} block (and I've never come across such a case). For abitrarily complex index calculation I'd do something like this:
my $get_next_idx = make_index_iterator(\@array);
while(my $i = $get_next_idx->()) {
local *_ = \ $array[$i];
# $_ is aliased here
}
(Note how the point about
($_) for
BrowserUk's code doesn't apply as
$i is an array index, not an array element.)
Makeshifts last the longest.