Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Noobie hash-value question

Status
Not open for further replies.

wraheem

MIS
Jul 19, 2001
62
US
Basically I'm getting a list from output from a command that lists a process, who owns it, how long it's been used etc. I learned how to put this info into a hash and sort the info by the value so that I get the top users in order by the number of processes or open, similar to:

user3 5processes
user1 4processes
user6 3processes

What I am trying to do is have email sent to me that once a user gets 4+ processes or maybe kill one of those processes so that other users can gain access.

My question is how to use the value of the hash as a variable to run a simple
if ($processvalue >= "4") then do what I need.

I saw some info on how to do something similar using each(), but it seemed to be focused on the key not the value.

Any help would be appreciated.
 

Assuming the hash is
[ user1 => 2,
user2 => 3,
user3 => 6,
user4 => 4,
.
.
.
]

This will loop through the hash, greatest num of processes running to the least, exit the loop, once all users with >=4 processes have been processed.

Code:
foreach my $key (reverse sort {$hash{$a} <=> $hash{$b}} keys %hash){
    last unless($hash{$key} >= 4){
         &sendEmail();
    }
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top