I want to loop over an array of strings, but sometimes if the string is empty, it still gets added as an item.
my $forename = $service->getValue('forename');
my $surname = $service->getValue('surname');
my @selectedNames = ( $forename, $surname );
foreach my $name (@selectedNames) {
# do something
if ($trackedName) {
# log the name
} else {
# log a FATAL
}
}
If the string is empty for $surname, then it shouldn't loop the second time at all, but it always does. How do I prevent this?