in reply to Re^2: Error Handling the Perl script
in thread Error Handling the Perl script

Create an errorlist the same as nodelist

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); }
And return the value to main
my ($nodelist,$errorlist) = get_node($path.'serverlist.txt');
and add line after clearing server list
print_log("There were ".scalar @$errorlist." errors in serverlist");

delete the process_error code.

poj

Replies are listed 'Best First'.
Re^4: Error Handling the Perl script
by shroh (Acolyte) on Aug 14, 2015 at 18:46 UTC
    Hi Poj, Thanks for analysing the script. But when i am calling the subroutine i am only calling like this: my @nodes=get_node(); How do i retrun @nodelist,@errorlist to the same subroutine when i am not passsing any argument to the argument while calling it. Also when i return the reference to the array, it gave me some kind of memory error.