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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is my value in hash keys ? 1

Status
Not open for further replies.

MoshiachNow

IS-IT--Management
Joined
Feb 6, 2002
Messages
1,851
Location
IL
HI,

I need to check if $PID2 is anywhere in keys of hash %$existing.
Can I use something like :
unless ($PID2 in keys %$existing) {

instead of looping each time :

for (keys %$existing) {
if ($PID2 eq $_) {

?
thanks

Long live king Moshiach !
 
You can use the grep function.

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::PerlDesignPatterns)[/small]
 
As long as $existing{$PID2} has a non-zero value, you can do it with:
Code:
if ($existing{$PID2}) {
  # It exists
} else {
  # It doesn't exist
}
 
The method ChrisHunt suggests is the correct one to use.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top