in reply to Excel editing perl

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.

True laziness is hard work

Replies are listed 'Best First'.
Re^2: Excel editing perl
by tarunkhanna (Novice) on Sep 29, 2011 at 11:38 UTC
    Hi, I even tried keep that global variable as local and passing it as parameter to the required function. But it produces the same result. The problem is :-

    If I generate 10 charts, 9 charts are correct.

    But the last chart has problem. The labeling done at x-axis of last chart is missing every alternative attribute.

    what shall i do to resolve this issue??

    Regards

      The advice from GrandFather about global variables was not about correcting your bug but making your script a) debuggable and b) readable by others.

      The next thing to do is either a) use print statements or the built-in debugger to tell you for example what data the subroutine gets per invocation and what it does with it or b) reproduce your refinded script on this website to let perlmonks help you with the search for the bug (ideally a minimal(!) runable(!) script that shows the problem)

        Hey, I used the debugger and I did tracing too. The point is :-

        we have a graph in which we have x-axis. x-axis is labeled 1,2,3,4,5 and so on. When my script runs, it does labeling everytime the function is called. But it doesn't do labeling last time function is called.

        The point is those label values are there in the excel. If I right click on the x-axis attributes and click on select data, all the attributes can be seen. But all those attributes are not there if i see the graph.

        Right Clicking on the attributes of same graph and select data shows all the attributes but directly it doesn't show attributes.