diff --git a/gedcom b/gedcom index dad7bee..f0569be 100755 --- a/gedcom +++ b/gedcom @@ -8449,7 +8449,7 @@ sub all_records_have_date # Check if the date is valid and matches required format if((!defined $date) || ($date !~ /^\d/) || ($date =~ /[a-z]$/i) || ($date =~ /[\/\-]/) || ($date =~ / to /) || !date_parser_cached(date => $date)) { - if(defined($date)) { + if((defined($date)) && ($date !~ / to /) && ($date !~ /[\/\-]/)) { # Log a warning if date is invalid complain({ person => $person, @@ -9641,36 +9641,30 @@ sub Gedcom::Individual::relationship_down sub stepsabove { - my $person = shift; - my $target = shift; - my $count = shift; - - return -1 if($count == -1); + my ($person, $target, $count) = @_; + $count ||= 0; # Ensure count has a default value if not provided. - if(!defined($target)) { + # Validate inputs + if((!defined $person) || !defined $target) { print STDERR "\n"; my $i = 0; - while((my @call_details = caller($i++))) { - print STDERR "\t", colored($call_details[2] . ' of ' . $call_details[1], 'red'), "\n"; + while (my @call_details = caller($i++)) { + print STDERR "\t", colored("$call_details[2] of $call_details[1]", 'red'), "\n"; } die 'Usage: stepsabove($person, $target, $count)'; } - if($person->xref() eq $target->xref()) { - return $count; - } - - my @father = $person->father(); - if(my $father = $father[0]) { - my $rc = stepsabove($father, $target, $count + 1); - return $rc if($rc != -1); - } + # Found the target + return $count if $person->xref() eq $target->xref(); - my @mother = $person->mother(); - if(my $mother = $mother[0]) { - return stepsabove($mother, $target, $count + 1); + # Recursive calls for father and mother + for my $parent($person->father(), $person->mother()) { + next unless defined $parent; # Skip undefined parents + my $rc = stepsabove($parent, $target, $count + 1); + return $rc if $rc != -1; # Return result if found } + # Target not found return -1; }