title: How can I use a variable as a module name in Perl?
body: <p>I know it is possible to use a variable as a variable name for package variables in Perl.  I would like to use the contents of a variable as a module name.  For instance:</p>
  
  <pre><code>package Foo;
  our @names =("blah1", "blah2");
  1;
  </code></pre>
  
  <p>And in another file I want to be able be able to set the contents of a scalar to "foo" and then access the names array in <code>Foo</code> through that scalar.  </p>
  
  <pre><code>my $packageName = "Foo";
  </code></pre>
  
  <p>Essentially I want to do something along the lines of:</p>
  
  <pre><code>@{$packageName}::names; #This obviously doesn't work.
  </code></pre>
  
  <p>I know I can use</p>
  
  <pre><code>my $names = eval '$'. $packageName . "::names" 
  </code></pre>
  
  <p>But only if <code>Foo::names</code> is a scalar.  Is there another way to do this without the <code>eval</code> statement?</p>