is it possible you can remove the invalid names before going through the list? for example create a new array with the valid names.. find the number of them and then test the id against the array element in your subroutine:
my @raw_names = ...;
my @valid_names = ();
my $total_valid_names = -1;
foreach my $raw_name(@raw_names){
next unless $raw_name;
push(@valid_names,$raw_name);
$total_names++;
}
for(my $i=0;$i<length(@valid_names);$i++){
check_name($valid_names[$i],$i);
}
sub check_names{
my($name,$id) = @_;
if($id == $total_valid_names){
say "$name is the last name! ($idth)";
}
}
|