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

I'm doing some dirty quick scripting to prototype something. I don't have very much time so I won't use Moose or anything like that. I'm doing in somefile.pl:
require 'otherfile.pl';
and in otherfile.pl I have
require Exporter; my @p = blabla; our @EXPORT_OK = (@p);

I'm expecting to be able to use the same @p in somefile.pl but it seems I can't.

how can I make this work the dirty dirty quick quick way ?

thanks

Replies are listed 'Best First'.
Re: importing arrays from other module
by Corion (Patriarch) on May 12, 2010 at 08:04 UTC

    You can't export lexical variables to other modules by using Exporter. So make @p a global variable, and change your otherfile.pl into a Perl module by giving it its own package statement, changing the extension to .pm and then loading it via use.

    I just now see that also your syntax for using Exporter is wrong. Even if you're in a big hurry because your homework is due any minute now, consider posting some real yet short example that replicates what you have now instead of making up things and leaving out important details.

Re: importing arrays from other module
by JavaFan (Canon) on May 12, 2010 at 09:45 UTC
    If it's just quick and dirty, then don't use packages. In otherfile.pl, do:
    our @p = (1, 2, 3, 4, 5);
    and in somefile.pl:
    require "foo.pl"; our @p; print "@p\n";
    No import/export needed (as you're using just one namespace). Of course, if you're really dirty, you can leave out the our as well - just make sure you aren't using strict either (or use full path names).
Re: importing arrays from other module
by Anonymous Monk on May 12, 2010 at 08:04 UTC
    I forgot to mention that I've already read that Exporter documentation says explicitly not to import arrays but I'm not really in the mood of respecting that, I want a dirty-quick type of solution.

      Maybe you don't want to use Exporter at all then? You keep on harping that you want "dirty-quick", but you don't tell us what you really want to do. The dirtiest way to create names for variables in another package is:

      *main::p = \@p;

      ... but then, it's really not clear to me what you're trying to do at all.