in reply to Using variables declared in a library from other perl scripts

Given a module file nonam1.pm containing:

use strict; use warnings; package noname1; our $wibble = 'Hello World'; 1;

then a Perl source file in the same location containing:

use strict; use warnings; BEGIN { require "./noname1.pm"; } print $noname1::wibble;

prints:

Hello World

as does:

use strict; use warnings; use noname1; print $noname1::wibble;

Update: Remove broken and needless cruft from module code (see anno's reply).


DWIM is Perl's answer to Gödel

Replies are listed 'Best First'.
Re^2: Using variables declared in a library from other perl scripts
by Anno (Deacon) on Apr 19, 2007 at 08:59 UTC
    use EXPORTER; package noname1; our @EXPORT_OK = qw($wibble); our $wibble = 'Hello World'; 1;
    You must be on a case-insensititve file system. It should be "use Exporter;". But "Exporter" does nothing in your code. It would work exactly the same without "use Exporter;" and without setting "@EXPORT_OK".

    What happened? Your replies are usually more to the point.

    Anno

      Late afternoon brain fade and rush due to demands of $work are the only excuse I can give. :(

      Node updated.


      DWIM is Perl's answer to Gödel
Re^2: Using variables declared in a library from other perl scripts
by linuxfan (Beadle) on Apr 19, 2007 at 00:21 UTC
    Thanks very much - the above code works very well for my needs.

    Cheers