I'm dealing with instances of the error: Variable "$Need_msg" will not stay shared at ./find_deps_from_errs.pl line 1211. Variable "$newpkg" will not stay shared at ./find_deps_from_errs.pl line 1216.
I turned on diagnostics, and believe I understand what it thinks I am trying to do, but what it thinks I am trying to do isn't what I am doing (maybe the diagnostics are misleading me in all this...bug anyway...)
I have a case where I'm using a subroutine within an enclosing block within another subroutine that is accessing a variable outside the "enclosing subroutine's enclosing block, but inside the outer subroutine.
My intention is that it be 'global' inside the outer subroutine, yet perl (according to the diagnostics message) seems to be trying to make the variable part of a closure -- even though it's not a variable that goes out of scope at the end of the inner subroutine -- so it shouldn't, as far as I can tell, be trying to make a closure out of it.
Here's the raw code of the *section* in question. I'm actually getting the error on two variables at this point.
Variables "$Need_msg" and "$newpkg" below.
Note -- I don't need to know how to 'fix' or get around the problem. This isn't that type of problem -- its a case of why doesn't it work the way that I think it should work (I'm coming from working code and playing with different ways of "restructuring" it.
The error message comes at places where the affected variables are used within the body of "sub do_pkg_need_from_Dist".
sub process_need_from_Dist ($$\@) { my ($Rpmcmd, $Distdb, $argsp)=@_; my ($need, $insted, $rpm_nvra) = @$argsp; unless (length $insted) { $insted=0 } my $rqng_pkg; return undef unless $rqng_pkg=Pkg->by_rpm_nvra($rpm_nvra); my $Need_msg = sub ($) { Inf($_[0] ." needed by " . ($insted ? "(installed) " : "") . $rqng_nvra . "\n"); }; my $newpkg; { my ($rq_nam, $rq_vr, $rq_op); sub do_pkg_need_from_Dist($$$$) { my ($Distdb, $rq_nam, $rq_vr, $rq_op)=@_; my ($rq_v, $rq_r); if ($rq_vr) { # see if rq_vr contains rq_v & _r my @args=split_vr($rq_vr); if (@args == 2) { ($rq_v,$rq_r)=@args } else { $rq_v=$rq_vr } $Need_msg->(sprintf "Pkg %s %s v=%s, r=%s", $rq_nam, $rq_op, $rq_v, sp($rq_r) ); } # need exact pkg case if ($rq_v && $rq_op eq '=') { # exact pkg-nv[r] search $newpkg=$Distdb-> find_n_v_r_to_pkg($rq_nam,$rq_v,$rq_ +r) or do {Serious "find_n_v_r_to_pkg failed\n";return + undef}; } else { # version free search...validate >= after return $Need_msg->("Pkg $rq_nam, any_ver") if !defined $rq_op +; $newpkg = $Distdb->find_rpmnam_to_pkg($rq_nam) or do { Serious "find_rpmnam_to_pkg failed\n"; return unde +f }; if ($rq_vr && cmp_vr_strs($newpkg->vr, $rq_vr) < 0) { Serious "Pkg nvr '",$newpkg->nvr,"' not >= '$rq_vr +'\n"; return undef; } return $newpkg; } } { my $need_re1 = qr{(\S+)\s(>?=)\s(\S+)}; my $need_re2 = qr{^[^\.]+$} ; ($rq_nam, $rq_op, $rq_vr) = $need=~/$need_re1/ or ($need=~/$need_re2/ and $rq_nam=$need); } if ($rq_nam) { $newpkg=do_pkg_need_from_Dist($Distdb, $rq_nam, $rq_vr, $rq_op); } elsif ($newpkg=$Distdb->find_rpm_owning_file_to_pkg($need)) +{ $newpkg->add_file($need); } else { Serious "find_rpm_owning_file_to_pkg failed\n"; return undef } } }
In reply to Perl scoping not logical...? by perl-diddler
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |