The first thing I would do is remove all the global variables. It's not possible for us to diagnose your issue because we can't tell what may affect the global variables outside the scope of add_chart_func.
There are various ways you can remove the need for global variables. The most obvious thing is simply to pass everything in as parameters. With the seven or so global variables used here that's getting to be a fairly large number of parameters to keep track of, but is an easy first step. Of course some of those variables are updated and there are several ways you could handle that too, but the simplest is probably just to return the updated values. Consider:
sub Main { my $workbook; my $name; my $Graph_table_last_row; my $row; my $var1; my $var2; my $grpsheet; my $graph_table_no; ... ($Graph_table_last_row, $graph_table_no) = add_chart_func ($workbook, $name, $Graph_table_last_row, $row, + $var1, $var2, $grpsheet, $graph_table_no); ... } sub add_chart_func { my ($workbook, $name, $Graph_table_last_row, $row, $var1, $var2, $ +grpsheet, $graph_table_no) = @_; ...; $Graph_table_last_row = $row + 5; $graph_table_no++; return $Graph_table_last_row, $graph_table_no; }
which has the advantage of explicitly showing the variables used by each sub and showing which variables are updated by each sub. If refactoring your code in that fashion doesn't turn up the problem then you need to mock up the Excel related calls in some fashion and post code we can run (without needing Excel or any OLE related modules) that demonstrates the problem you are seeing.
In reply to Re: Excel editing perl
by GrandFather
in thread Excel editing perl
by tarunkhanna
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |