Your core problem is here:
if (exists $colD{$valA}) { ... elsif (! exists $colD{$valA}) { ... }
Clearly, if exists $colD{$valA} is false, then its negation must be true:
if (exists $colD{$valA}) { ... else { ... }
However, as you never set $colD{$valA}, the condition will always be false and the else block will only ever be entered.
There are lots of other issues with this code. Here's a non-exhaustive list in no particular order.
Add use warnings; - right after use strict; is a good place. If you're having trouble understanding the messages, add use diagnostics; for more verbose messages. Relevant documentation: warnings and diagnostics.
... use strict; use warnings; use diagnostics; ...
Your indentations appear almost totally arbitrary and your use of whitespace seems quite erratic. This makes reading your code difficult but it doesn't need to be. Please read: perlstyle.
There's a number of places where some sort of naming convention would have helped you. For instance, you use three variables for worksheet objects: $sheet, $worksheet1 and $worksheet. Except where you declare and assign these, they don't convey a lot of meaning. Perhaps $sheet_in and $sheet_out would have been more informative. And yes, that is two new names for three existing variables: another bug in your code that I just found!
Instead of open FILE ..., use something like open my $whatever_fh .... See open for a discussion of this.
You have the identical statement my $valA = $sheet->{Cells}[$row][0]->{Val}; in both blocks of your if-else code. This would be better as:
my $valA = $sheet->{Cells}[$row][0]->{Val}; if (exists $colD{$valA}) { ...
That should be enough for you to get your code working. If you need to ask further questions, please first read: How do I post a question effectively?
-- Ken
In reply to Re: struggling with spreadsheet::WriteExcel and writing columns
by kcott
in thread struggling with spreadsheet::WriteExcel and writing columns
by trickyq
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |