parse_header

Input

Worksheet, where the first line contains these headers:

KEY GLO LOC CPC GROUP

Internal data

We have a table, representing the mapping between words from the worksheet and other words.

word 1word 2
KEYword
GLOglobal_monthly_search
LOClocal_monthly_search
CPCCPC
GROUPgroup

Output

Array, containing the mapped words in the order, corresponding to the order of the original names:

word global_monthly_search local_monthly_search CPC group

If the order of names in the input row changes, order of the columns in the result array must change correspondingly.

Code

sub parse_header
# {{{
{
      my $worksheet = shift;

      my %values = (
            "KEY" => "word",
            "GLO" => "global_monthly_search",
            "LOC" => "local_monthly_search",
            "CPC" => "CPC",
            "GROUP" => "group",
        );

      my $n = keys(%values);
      my @result;

      for (my $i = 0; $i < $n; $i++) {
            if(defined($values{$worksheet->{Cells}[0][$i]->value}))
            {
                  push(@result, $values{$worksheet->{Cells}[0][$i]->value});
            }
      }

      return \@result;
}
# }}}