Skip to content

Commit

Permalink
Refactor country()
Browse files Browse the repository at this point in the history
  • Loading branch information
nigelhorne committed Nov 7, 2024
1 parent 8e955e5 commit 88d1bbe
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions createdatabase.PL
Original file line number Diff line number Diff line change
Expand Up @@ -4760,21 +4760,22 @@ sub country
{
my($file, $state) = @_;

# Ensure the file argument is provided
die if(!defined($file));

if($file =~ /north-america/) {
return 'US'
}
if($file =~ /australia/) {
return 'Australia'
}
# Check for file patterns and return corresponding country
return 'US' if $file =~ /north-america/;
return 'Australia' if $file =~ /australia/;

die if(!defined($state));
# Ensure the state argument is provided if needed
die "State argument is missing" if not defined $state;

if($file =~ /europe/) {
if(($state eq 'Georgia') || ($state eq 'GA') || (uc($state) eq 'DE') || ($state eq 'VI')) {
return $state
}
# Handle European cases with specific state codes
if ($file =~ /europe/) {
my %valid_states = map { $_ => 1 } ('Georgia', 'GA', 'DE', 'VI');
return $state if $valid_states{$state} || $valid_states{uc($state)};
}
die "$file/$state"

# Default case: Raise error with both file and state information
die "$file/$state";
}

0 comments on commit 88d1bbe

Please sign in to comment.