Hi Experts,
I have a requirement which leads me to return more than two arrays to the subroutine which is called from the main subroutine.
a) array @nodelist is holding all the server names on which i am running some actions using the script.
b) array @errorlist is holding all the server names on which actions failed. From getting the number of elements in @errorlist i need to finally spit in the logs the total number of servers which failed out of total. Below is the code snippet which i am using to return 2 arrays. But somehow this is not working. Instead of passing the array itself i am passing the reference to the array which is also giving some memory errors. I am not sure why. Any ideas are highly appreciated.
sub main {
my $path = 'E:/scripts/OutageNodes/';
require $path.'omwNodeDetails.pm';
open_log($path.'maintenanceMode_');
my $mode=get_mode();
my ($nodelist,$errorlist) = get_node($path.'serverlist.txt');
if( $mode eq 'enable'){
enable_unplanned_outage(@nodes);
}
elsif($mode eq 'disable'){
disable_unplanned_outage(@nodes);
}
else {
printLog("Error invalid Mode $mode");
}
# clear serverlist
printLog ("Truncating serverlist");
open( SRV,'>',$path.'serverlist.txt')
or die "Can't open SRV '$path.serverlist': $!";
close SRV;
close_log();
printLog("there were ".scalar @$errorlist." errors in serverlist");
}
sub get_node {
my ($infile) = @_;
my @nodelist = ();
my @errorlist = ();
##checks if the file exists and pulls the info out
if (-e $infile){
open INFILE, '<', $infile or die "Could not open $infile : $!";
print_log("Scanning $infile");
while (my $node = <INFILE>){
chomp($node);
my ($hostname) = split /\./, $node;
my $fqdn = getNodeAttributes($hostname,'PrimaryNodeName');
if (length($fqdn) < 1) {
print_log("No value returned from WMI, node ($node) doesn't ex
+ists in OMW.");
push @errorlist,$node;
} else {
print_log("$node => $hostname => $fqdn");
push @nodelist,$fqdn;
}
}
close INFILE;
}
else {
print_log("ERROR Cannot open $infile");
}
return (\@nodelist,\@errorlist);
}