If you look at this code...

By "this code", I assume you mean the code posted at the end of the Re^2: variable scopes in Excel::Writer::XLSX node, and that this code is all that is needed to produce the error you describe. (I'm not in a position right now to run the code; all I can do is literally 'look' at it.)

... I see no reason that the one extra assignment should cause an error.

Nor do I. The  $closure_workbook variable is never touched except to assign it a value in certain circumstances. It is never otherwise accessed within  func() and no other function than  func() can possibly access this lexical variable (unless there's something you're not showing us). The next step is to eliminate the
    if (@_) {
        $closure_workbook = $book;
    }
block of code (leaving the  my $closure_workbook; statement just for grins) and see if the error still occurs. My bet is it will. This means the root cause of your problem is entirely unconnected to anything you're doing with this 'closure' variable.

For a while, I had my suspicions about the  &func(@ARGV); ampersand invocation of  func(), but I can't see this has any relevance.

Update: Oops... Should have refreshed the thread before posting. I see from Re^4: variable scopes in Excel::Writer::XLSX that the problem is resolved. At any rate, the problem had, indeed, nothing to do with anything that was happening with the 'closure' variable.


In reply to Re^3: variable scopes in Excel::Writer::XLSX by AnomalousMonk
in thread variable scopes in Excel::Writer::XLSX by johnrcomeau

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.