This is driving me mad, where am I going wrong?
The relevant segment of code:
Code:
sub getndsybcons {
my @servers=@{$_[0]};
my @sybservers=@{$_[1]};
my %results;
foreach my $server(@servers) {
my $biggestsyb;
my $biggestsybval=0;
foreach my $sybserver(@sybservers) {
open(NETSTAT,"$config{'su'} - $config{'user'} -c \'ssh $server \"netstat -a\"\' | grep $sybserver | wc -l|") || return;
while(<NETSTAT>) { $tempval=$_ }
if ($tempval > $biggestsybval) {
$biggestsybval=$tempval;
$biggestsyb=$sybserver;
}
}
if ($biggestsybval > 5) {
$results{$server}=$biggestsyb;
} else {
$results{$server}="";
}
}
return %results;
}
The error:
Code:
Can't use subscript on private hash at ./ib-lib.pl line 22, near "$server}"
(Did you mean $ or @ instead of %?)
Can't use subscript on private hash at ./ib-lib.pl line 24, near "$server}"
(Did you mean $ or @ instead of %?)
Lines 22 and 24 are bolded.
This code is for a webmin module to control an application's various components.
This bit of perl is part of a library of functions called by the main GUI interface code. Webmin provides the %config structure.
I've never been that great with hashes at the best of times but this one's got me really boggled.
It feels like I've got my variable declarations wrong (I'm attempting to minimise global variables that are not used as constants (eg %config), but have been finding this rather fiddly as I'm _very_ rusty at "real" coding

) but I don't seem to be getting anywhere playing round with it...
Can someone cast some light on this for me?