- or download this
# Verify $prev is NON-empty
if ($prev) { ... }
- or download this
# straightforward approach: track whether this
# is the first iteration or not explicitly.
...
}
$prev = $elem;
}
- or download this
# note that this alters @array
my $prev = shift @array;
...
push @result, compute( $elem, $prev );
$prev = $elem;
}
- or download this
my ( $prev, @rest ) = @array;
foreach my $elem ( @rest )
...
push @result, compute( $elem, $prev );
$prev = $elem;
}
- or download this
my $prev = $array[0];
foreach my $elem ( @array[ 1 .. $#array ] )
...
push @result, compute( $elem, $prev );
$prev = $elem;
}
- or download this
# note that we want $i to stop one short of $#array,
# since we access $array[$i+1].
...
{
push @result, compute( $array[$i+1], $array[$i] );
}