I think I know the answer, but I haven't found confirmation...

I have a closure with 3 subs in it, something like this:

use strict; use warnings; { # closure my %foo; sub collect_it { my ($key, $value) = @_; $foo{$key} = $value; } sub print_it { for my $key ( keys %foo ) { print "\$foo{$key} = $foo{$key}\n"; } clear_it(); } sub clear_it { %foo = (); } } # end closure
The script compiles and runs with no warnings or errors, and appears to "do the right thing".

However, some of my users want a PAR executable. When making the PAR executable (pp -z 9 -c script.pl), I get errors for all of the enclosed lexicals:

Variable "%foo" will not stay shared at 60oehl line 123.
...where line "123" is a line in "script.pl" that references %foo.

From my reading I see that this error comes up in Perl when using nested named subs, which isn't the case here.

The only thing I can think of is that PAR is somehow wrapping my whole script, which then triggers the sharing warning message under "-c".

I've tried to reproduce this with a smaller script, but had no luck yet. (The original script is 1000+ lines.) I'm also wondering if the "\$foo{$key}" confuses the compiler into thinking that's a reference?

Any hints?

-QM
--
Quantum Mechanics: The dreams stuff is made of


In reply to PAR: Variable %x will not stay shared by QM

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.