I can't find any reason why you would get that particular error. But I
have a few comments.
Always use strict and use warnings (or -w)
> package Config;
This should really be 'package MARS::Config;' - there is already a
'Config' namespace in core Perl.
And then in your script '%CONFIG = MARS::Config->new;
> require Exporter;
> @ISA = qw(Exporter);
> @EXPORT = qw( new );
There's no need for exporter here but if you decide to use it then your
script could do this:
%CONFIG = new;
but you wouldn't know what 'new' thing you were creating?
> sub new
> {
> my %CONFIG;
> open(CNF, "./api.cnf");
You should test to make sure there were no errors with open() - I
suspect this is what's causing your problem!
open(CNF, "./api.cnf") or die "Error opening config file './api.cnf':
$!\n";
> while(<CNF>)
> {
> next if($_ =~ /^\#/);
> ($bef, $var)= split(/=/);
These should really be local my() variables
> chomp($bef, $var);
No need ot chomp $bef
> $CONFIG{$bef} = $var;
> }
> close(CFN);
> return(%CONFIG);
> }
> 1;
Also you might want to consider using an object interface - it makes
life much easier as your module grows, something like this should get
you going:
package MARS::Config;
use strict;
use Carp;
my $config_file = './api.cnf';
sub new {
my $class = shift;
my $self = bless {}, ref($class)||$class;
$self->init();
return $self;
}
sub init {
my $self = shift;
open(CNF, "$config_file")
or croak "Error opening config file '$config_file': $!\n";
while(<CNF>) {
next if($_ =~ /^\#/);
chomp;
my ($bef, $var) = split(/=/);
$self->{$bef} = $var;
}
close(CFN);
}
1;
and the script now looks like this:
use strict;
use warnings;
use MARS::Config;
use Data::Dumper;
my $CONFIG = MARS::Config->new();
# note that new() returns a MARS::Config object, which is simply a
blessed hash ref.
print Dumper(\$CONFIG);
print $@;
--
Simon Oliver
_______________________________________________
Perl-Win32-Web mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-web