Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

PAR: Variable %x will not stay shared

by QM (Parson)
on May 25, 2006 at 03:37 UTC ( [id://551496]=perlquestion: print w/replies, xml ) Need Help??

QM has asked for the wisdom of the Perl Monks concerning the following question:

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

Replies are listed 'Best First'.
Re: PAR: Variable %x will not stay shared
by Joost (Canon) on May 25, 2006 at 12:00 UTC
      It seems to be more complicated than just "PAR wraps your script in a subroutine, and that's the source of the problem." If that were the case, then any program that uses the cache/closure idea should cause the warnings.

      The toy script in the OP generates the warnings, but another script where I did something similar did not.

      So I'll have to work up an example along the lines of the toy script, but doesn't generate the warnings, and show the minimum tweak that does generate the warnings. (Or some kind soul can chime in with a satisfying explanation.)

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

Re: PAR: Variable %x will not stay shared
by sgifford (Prior) on May 25, 2006 at 05:24 UTC
    Does:
    no warnings 'closure';
    solve your problem?

    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'm not intimately familiar with PAR, but that seems fairly likely.

    I've tried to reproduce this with a smaller script, but had no luck yet.
    So does the short script you give above reproduce the problem, or no?
      I've tried to reproduce the problem with a smaller script, but no warnings/errors are generated.

      I need to look into some of the modules I'm using, to see if there's any effect there. The toy script doesn't use them, but also doesn't have the problem.

      BTW: Yes, no warnings 'closure'; fixes it.

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

Re: PAR: Variable %x will not stay shared
by PodMaster (Abbot) on May 25, 2006 at 03:50 UTC
    Any hints?
    Ignore it :)

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://551496]
Approved by Tanktalus
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-06-14 08:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.