in reply to Perl's feature to determine, in current point of loop, that this is the last one?
Replace
withfor my $x ( ... ) { ... if ( ??? ) { ... } ... }
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.
|
---|
In Section
Seekers of Perl Wisdom