> No. You should't export it. "Exporting" means making an > "alias" to the variable in the package that issues the "use". > > If you refer to the variable as $Package::Error, you don't > need to export it. If you export it, you would refer to it as > simply $Error. But that might interfere with the main > program's use of $Error in some other context. > > You can put $Error in the @EXPORT_OK array, which gives the > main program the > *option* to import the symbol if the author chooses. > > > > > if(!function()) { print "It failed and here is why - > > $Package::Error"; } else { print "It worked oh happy days"; } > > Yes, that's fine. > > > > > # or after executing function() > > > > if($Package::Error) { print "It failed and here is why - > > $Package::Error"; } else { print "It worked oh happy days"; } > > > > #Package.pm > > > > package Package; > > ... Export $Package:Error and function() > > my $Package::Error; > > No. You can't access "my" variables outside this file. It should be a > global: > > our $Error; > > > > > sub function { > > undef $Package::Error; # in case it was given a value > earlier in the > > Since you're in package Package, you don't need to qualify > this. You can just use $Error throughout. > > > script my $r = 1; # unless it fails return 1 > > if(it failed to work) { > > $r = 0; # it failed so return 0 > > $Package::Error = "IT failed because ...."; # > > set the reason why into the Erro Variable > > Same as above. > > > } > > return $r; > > } > > Example: > > Foo.pm: > > package Foo; > > use strict; > use base qw/Exporter/; > > our $Error; > our @EXPORT_OK = qw/bar $Error/; > > sub bar { > undef $Error; > my $aligned = 0; > $Error = "Frobnitz misaligned", return unless $aligned; > 1; > } > > 1; > > main.pl > > #!/usr/bin/perl -w > use strict; > use Foo qw/bar/; > > bar() or die $Foo::Error; >
Cool, thanks for the info. I'll experiment with that. Dan -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]