http://qs321.pair.com?node_id=11140741


in reply to Perl's feature to determine, in current point of loop, that this is the last one?

Replace

for my $x ( ... ) { ... if ( ??? ) { ... } ... }
with
my @a = ...; for my $i ( 0 .. $#a ) { my $x = $a[$i]; ... if ( $i == $#a ) { ... } ... }

This will work too:

my @a = ...; for my $x (@a) { ... if ( \$x == \$a[-1] ) { ... } ... }

Warning: As LanX pointed out, the last snippet fails if two elements of the array are aliases of the same scalar.


Update: Added warning.