# return a list consisting of correct division and service
# as a function of $dcr_type and @row
sub division_service {
my $dcr_type = uc shift;
my $row = shift; # you were copying an array here. not necessary
if ($dcr_type eq 'CONTACT') {
return ('HQ' , undef);
}
elsif ($dcr_type eq 'FAQ') {
return (undef, $row->[2] eq 'Service' ? $row->[3] : $row->[4]);
}
elsif ($dcr_type eq 'LITERATURE') {
return (undef, $row->[4]);
elsif ($dcr_type eq 'ORGANIZATION') {
return (($row->[0] eq 'Headquarters' ? 'HQ' : $row->[2]), undef);
}
else {
croak "Unknown \$dcr_type '$dcr_type'";
}
}
####
# return a list consisting of correct division and service
# as a function of $dcr_type and @row
sub division_service {
my $dcr_type = uc shift;
my $row = shift;
return
$dcr_type eq 'CONTACT' ?
('HQ' , undef) :
$dcr_type eq 'FAQ' ?
(undef, $row->[2] eq 'Service' ? $row->[3] : $row->[4]) :
$dcr_type eq 'LITERATURE' ?
(undef, $row->[4]) :
$dcr_type eq 'ORGANIZATION' ?
(($row->[0] eq 'Headquarters' ? 'HQ' : $row->[2]), undef) :
croak "Unknown \$dcr_type '$dcr_type'";
}
####
# return a list consisting of correct division and service
# as a function of $dcr_type and @row
sub division_service {
my $dcr_type = uc shift;
my $row = shift;
my %map = (
CONTACT =>
sub { 'HQ' , undef },
LITERATURE =>
sub { undef, $row->[4] },
FAQ =>
sub { undef, $row->[2] eq 'Service' ? $row->[3] : $row->[4] },
ORGANIZATION =>
sub { ($row->[0] eq 'Headquarters' ? 'HQ' : $row->[2]), undef },
);
return &{$map{$dcr_type} || croak "Unknown \$dcr_type '$dcr_type'"}();
}
####
BEGIN {
my ($row, %map);
# return a list consisting of correct division and service
# as a function of $dcr_type and @row
sub division_service {
my $dcr_type = uc shift;
$row = shift;
return &{$map{$dcr_type} || croak "Unknown \$dcr_type '$dcr_type'"}();
}
%map = (
CONTACT =>
sub { 'HQ' , undef },
LITERATURE =>
sub { undef, $row->[4] },
FAQ =>
sub { undef, $row->[2] eq 'Service' ? $row->[3] : $row->[4] },
ORGANIZATION =>
sub { ($row->[0] eq 'Headquarters' ? 'HQ' : $row->[2]), undef },
);
}