http://www.perlmonks.org?node_id=175087

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

I'm creating my first module, to reduce code redundancy in a project with several scripts.
I have read perldocs perlmod perlmodlib the Simple Module Tutorial and done a search on Google's advanced search, but haven't figured out yet what's going wrong.

I want a sub-routine in my module to access variables in main (and I would also like to be able to access variables in my config file with calls such as $conf->{'db_database'} but that isn't working either.

test.pl
#!/usr/bin/perl -wT use strict; use lib '/home/4220/straitwa/www.straitway.net/shop_34/lib'; use Shop; my (%conf, $conf, $dbh, $sth, $rc, @db_conf); #open the config file and parse it unless ($conf = do ('/home/4220/straitwa/www.straitway.net/shop_34/con +f.pl')) { die ("Could not open config file"); } my $one = $conf->{'db_database'}; print "Print - ", $one, " - from the main package\n"; Shop::db_connect;
The module Shop.pm
package Shop; use strict; use Exporter; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); $VERSION = 1.00; @ISA = qw(Exporter); @EXPORT = (); @EXPORT_OK = qw(db_connect); sub db_connect { print "Print - ",$main::one, " - from the Shop package\n"; } 1;
The resulting output is
Print - straitway_1 - from the main package Use of uninitialized value in print at /home/4220/straitwa/www.straitw +ay.net/shop_34/lib/Shop.pm line 13. Print - - from the Shop package
Any pointers? Thanks.
Edited by boo_radley : corrected anchor tag

edited - 17 June 2002 (footpad): Corrected another A tag problem.</small