in reply to Re^2: variable scopes in Excel::Writer::XLSX
in thread variable scopes in Excel::Writer::XLSX

People seem to be misunderstanding the point of my question..
Because what you intended is not clear. Closures in perl are not written like that. And you must have reason for what you are doing. You are calling a variable that is outside a function within the function, to assign to it an object. To what end? Oh I just want to call it. Is that not funny? Please take a look at the various suggestions already given. The solutions you wanted might be somewhere in the middle, if not already given.

  • Comment on Re^3: variable scopes in Excel::Writer::XLSX

Replies are listed 'Best First'.
Re^4: variable scopes in Excel::Writer::XLSX
by johnrcomeau (Novice) on May 25, 2013 at 18:22 UTC

    I misused the word 'closure' in my original post. I wanted to assign the workbook to a static variable. I believe that the structure I used is a commonly idiom in Perl for making a variable static.

    I never figured out why the error was occurring, but it disappeared when I explicitly called $workbook->close instead of letting the destructor handle it when the program exits. The workbook was also saved correctly.

      I misused the word 'closure' in my original post. I wanted to assign the workbook to a static variable. I believe that the structure I used is a commonly idiom in Perl for making a variable static.

      Yes that is old idiom, and yes, it is called a closure (Closure on Closures) because func closes over $closure_workbook, a lexical variable declared in outer scope.

      The new idiom is state / use feature qw' state ';

      OTOH, its not really static without this  unless(  $closure_workbook ) { if( @_ ) ... }