use strict;
use warnings;
package MyConfig;
use XML::Simple;
my $singleton;
my $XMLfile_name="";
my @hostList = ();
sub new {
my $class = shift;
#create singleton
$singleton ||= bless {}, $class;
#Error here: Useless use of hash element in void context
$singleton->{$XMLfile_name}=$_[0];
return $singleton;
}
sub loadConfig{
my $self=shift;
my $xml = XML::Simple->new;
my $config = $xml->XMLin($file_name,
ForceArray => [ 'host', 'component' ]) or die$!;
my $index=0;
while($config->{host}->{component}->[$index++])
{
push @hostList, $config->{host}->{component}->[0]->{component_name};
}
}
1;
####
####
use strict;
use MyConfig;
my $CONFIG = "somefile.xml";
&main;
sub main
{
my configReader = MyConfig->new( $CONFIG );
configReader->loadConfig;
}