title: package variable scope in module subroutine
body: <p>How do I change the value of a variable in the package used by a module so that subroutines in that module can use it?</p>
  
  <p>Here's my test case:</p>
  
  <p>testmodule.pm:</p>
  
  <pre><code>package testmodule;
  
  use strict;
  use warnings;
  require Exporter;
  
  our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
  
  @ISA = qw(Exporter);
  @EXPORT = qw(testsub);
  
  my $greeting = "hello testmodule";
  my $var2;
  
  sub testsub {
      printf "__PACKAGE__: %s\n", __PACKAGE__;
      printf "\$main::greeting: %s\n", $main::greeting;
      printf "\$greeting: %s\n", $greeting;
      printf "\$testmodule::greeting: %s\n", $testmodule::greeting;
      printf "\$var2: %s\n", $var2;
  } # End testsub
  1;
  </code></pre>
  
  <p>testscript.pl:</p>
  
  <pre><code>#!/usr/bin/perl -w
  use strict;
  use warnings;
  use testmodule;
  
  our $greeting = "hello main";
  my $var2 = "my var2 in testscript";
  
  $testmodule::greeting = "hello testmodule from testscript";
  $testmodule::var2 = "hello var2 from testscript";
  
  testsub();
  </code></pre>
  
  <p>output:</p>
  
  <pre><code>Name "testmodule::var2" used only once: possible typo at ./testscript.pl line 11.
  __PACKAGE__: testmodule
  $main::greeting: hello main
  $greeting: hello testmodule
  $testmodule::greeting: hello testmodule from testscript
  Use of uninitialized value $var2 in printf at testmodule.pm line 20.
  $var2:
  </code></pre>
  
  <p>I expected <code>$greeting</code> and <code>$testmodule::greeting</code> to be the same since the package of the subroutine is <code>testmodule</code>.</p>
  
  <p>I guess this has something to do with the way <code>use</code>d modules are <code>eval</code>d as if in a <code>BEGIN</code> block, but I'd like to understand it better.</p>
  
  <p>I was hoping to set the value of the variable from the main script and use it in the module's subroutine without using the fully-qualified name of the variable.</p>