I found below code in the PerlMonks and found quite helpful to read configuration(.cfg) file,
sub ReadCfg
{
my $file = $_[0];
our $err;
{ # Put config data into a separate namespace
package CFG;
# Process the contents of the config file
my $rc = do($file);
# Check for errors
if ($@) {
$::err = "ERROR: Failure compiling '$file' - $@";
} elsif (! defined($rc)) {
$::err = "ERROR: Failure reading '$file' - $!";
} elsif (! $rc) {
$::err = "ERROR: Failure processing '$file'";
}
}
return ($err);
}
# Get our configuration information
if (my $err = ReadCfg('my_cfg.cfg')) {
print(STDERR $err, "\n");
exit(1);
}
I tried running it with .cfg file where array @CFG holds list of hashes. its works,
Now I am having problem to understand what gets initialize in this process "my $rc = do($file);"
Suppose if after reading I want to pass the content of (@CFG) to another subroutine how can that be done?
I think I am totally lost, Any suggestion, Please.
Cheers,