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

**** update ****

Ok I figured out what was wrong...I had some old code in another package that was trying to export the wrong functions...and this was causing the errors. If I had just read the error message more carefully I would have saved myself about an hour of time hehe.....

*******************

I am exporting a function from a package. The function in question use a "my" var within the package. Whenever I call the exported function outside of the package I get an error that says the "my" var is not exported so the export failed. Am I doing something wrong here? I am never trying to call the "my" vars outside of the package itself...so no idea why I would be getting this error.

If I remove the export code and fully qualify the function calls then it works fine....

Here are some code snippets:

package BM::Constants::Address; ###################################################################### use strict; use base qw( Exporter ); our @EXPORT_OK = qw( COUNTRIES COUNTRY_NAME COUNTRY_HAS_REGIONS REGION +S REGION_NAME REGION_COUNTRY_ID CITIES CITY_REGION CITY_COUNTRY_ID ); ###################################################################### #look up tables my $country = undef; my $region = undef; my $city = undef; ###################################################################### sub COUNTRIES { my $active = shift; if(! defined $country) { my $db = BM::Database->new(); my $dbh = $db->db_connect(); my $sth = $dbh->prepare(" SELECT country_id, country_name, country_active FROM countries "); $sth->execute; while(my $row = $sth->fetchrow_arrayref) { $country->{$row->[0]} = { name => $row->[1], active => $row->[2], }; } $sth->finish; } if($active) { my %active_country = %$country; foreach my $key(keys %active_country) { delete $active_country{$key} if ! COUNTRY_ACTIVE($key); } return \%active_country; } return $country; } ###################################################################### sub COUNTRY_NAME { my $id = shift; $country = undef if ! exists COUNTRIES->{$id}; return COUNTRIES->{$id}->{name} ? COUNTRIES->{$id}->{name} : q{}; } ###################################################################### sub COUNTRY_ACTIVE { my $id = shift; $country = undef if ! exists COUNTRIES->{$id}; return COUNTRIES->{$id}->{active}; } ###################################################################### #rest of the functions were snipped...

Thanks for the help :-)

Replies are listed 'Best First'.
Re: Exporting Issue
by perlCrazy (Monk) on Jul 27, 2007 at 20:15 UTC
    MY variable cannot be called from outside of package. If you want to make package global variable then use 'OUR' or use vars module. Like this :
    use vars qw ($country); or our $country;
      Yeah I didn't want it accessible outside the package that is why it is a "my" var.