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

In reply to Re: Excel editing perl by GrandFather
in thread Excel editing perl by tarunkhanna

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.