A major shift of code is needed. Move the sub cell_handler to above the parser construction, and remove the name, making it anonymous.

The problem is that named subs are always global. They cannot bind to variables that are currently "in-scope" (in a surrounding function) that may go out of scope (calling cell_handler outside of the surrounding function). In short, global (named) functions cannot be closures.

# Excel parsing my $cell_handler = sub { # cell_handler contents go here. }; my $parse_excel = new Spreadsheet::ParseExcel(CellHandler => $cell_han +dler, NotSetCell => 1); #...

In reply to Re: Perl complaining about vars not staying shared by Tanktalus
in thread Perl complaining about vars not staying shared by Andre_br

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.