![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Development Releases: Linux Mint 4.0 Beta "Fluxbox", 4.0 Alpha "Debian" | iBot | UNIX and Linux RSS News | 0 | 01-04-2008 12:00 PM |
| Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`" | Lokesha | UNIX for Dummies Questions & Answers | 4 | 12-19-2007 10:52 PM |
| how could i make a program mixed with many "|", "<" and ">" | strugglingman | High Level Programming | 2 | 04-29-2006 05:11 AM |
| No utpmx entry: you must exec "login" from lowest level "shell" | peterpan | UNIX for Dummies Questions & Answers | 0 | 01-18-2006 01:15 AM |
| Adding "Private" to path name | roadrunnerray | UNIX for Dummies Questions & Answers | 5 | 10-15-2004 07:33 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
||||
|
||||
|
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;
}
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 %?) 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 Can someone cast some light on this for me? |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
I can't repro that. Do you have a global variable %results or a subroutine results elsewhere in your script? (Still can't repro with either of those, but I can't come up with anything better ...) Or just a missing closing brace somewhere -- those can trigger quite misleading error messages.
What's the point of an open("long pipeline |") loop if all you want is a single value? I'd use backticks for that. Also the return on error without a proper error message looks user-hostile and fragile. (Of course if the error checking is deferred to the caller then I suppose it's as it should be.) Last edited by era; 07-22-2008 at 10:15 PM. Reason: Suggest use backticks |
|
#3
|
|||
|
|||
|
hmm.... very weird. I think you should print the value or $server while the script runs, might help debug the problem. Just looking at the code I don't see any problem with syntax.
|
|
#4
|
||||
|
||||
|
Quote:
I've since got it running, by removing the 'my' keyword where it's setting $server if the foreach loop: Code:
my %results;
foreach my $server(@servers) {
my $biggestsyb;
my $biggestsybval=0;
|
|
#5
|
|||
|
|||
|
Me either, I can't see why that would make a difference. Is $server scoped to that block of code elsewhere in the script? What is the value of $server with "my" and without "my"?
|
|
#6
|
||||
|
||||
|
If I leave the 'my' in, it won't execute at all, if I leave it out, $server has the correct value. Very hard to debug....
|
|
#7
|
|||
|
|||
|
That just makes no sense from the code that you posted. What are the values in @servers?
|
|||
| Google The UNIX and Linux Forums |
| Tags |
| cgi, hash, perl, webmin |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|