Note that there are some explanatory texts on larger screens.

plurals
  1. POIs it possible to trick Perl to use a variable %INC and still keep the global %INC untouched?
    primarykey
    data
    text
    <p>I have just found a script we are using which has a sub that says <code>my %INC</code> in it, where it stores some values about incentives, thus <code>%INC</code>. This never seemed to be a problem, or no-one ever noticed. For me it produced 20 screens of redefine warnings, because <code>%INC</code>, holding all the file names Perl has <code>do</code>ne, <code>require</code>d or <code>use</code>d, was pretty large, and now is <code>('stuff' =&gt; 123)</code>.</p> <p>Do I really have to go and rename every single reference to this in the sub, or is there another way to make Perl forgive this ... ?</p> <hr> <p>Here's a part of the output of:</p> <pre><code>print Dumper \%INC; # I added this line my %INC; print Dumper \%INC; # I added this line exit; # I added this line </code></pre> <p>Output:</p> <pre><code> [...] 'SqlConnect.pm' =&gt; 'lib1/SqlConnect.pm', 'Lib/RateRequest.pm' =&gt; 'Lib/RateRequest.pm' }; $VAR1 = {}; [Fri Jun 29 16:09:13 2012] live_batch_test.pl: Subroutine export_fail redefined at /usr/lib/perl5/5.14.2/Carp.pm line 43. [Fri Jun 29 16:09:13 2012] live_batch_test.pl: Subroutine _cgc redefined at /usr/lib/perl5/5.14.2/Carp.pm line 45. [Fri Jun 29 16:09:13 2012] live_batch_test.pl: Subroutine longmess redefined at /usr/lib/perl5/5.14.2/Carp.pm line 51. [Fri Jun 29 16:09:13 2012] live_batch_test.pl: Subroutine shortmess redefined at /usr/lib/perl5/5.14.2/Carp.pm line 71. [...] (Snipped like 20 screens of redefine warnings) </code></pre> <p>The warnings only show if I create an object of one of my classes (which happens to contain <code>SOAP::WSDL</code> so it has a lot of stuff in it). I'm not sure why those are redefine warnings. If <code>%INC</code> is empty, how can it know stuff is being redefined?</p> <hr> <p><strong>Update:</strong></p> <p>It seems you actually <strong>can</strong> create a lexical <code>my %INC</code>.</p> <pre><code>use strict; use warnings; use Data::Dumper; print Dumper \%INC; { my %INC = ('asdf' =&gt; 'asdf'); print Dumper \%INC; } print Dumper \%INC; </code></pre> <p>Produces (snipped):</p> <pre><code> 'feature.pm' =&gt; 'C:/Perl/lib/feature.pm' }; $VAR1 = { 'asdf' =&gt; 'asdf' }; $VAR1 = { 'warnings/register.pm' =&gt; 'C:/Perl/lib/warnings/register.pm', </code></pre> <p>The problem in my case does not seem to be the <code>my %INC</code>, but rather the <code>%INC = &amp;sub_that_has_my_percent_INC_and_returns_it()</code> in the script that I actually have to <code>require</code>. Now that, in turn, also has <code>use vars qw(%INC)</code>. Replacing it... well, I'm not sure what that is going to break.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload