Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6338179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:23:31+00:00 2026-05-24T19:23:31+00:00

Is there a correct way of testing if a particular hash key has already

  • 0

Is there a correct way of testing if a particular hash key has already been assigned any value, even if this value is zero? I have been working with a statement like this:

%hash=();
$hash{a}=1;
$hash{b}=0;
if($hash{$key}) { do something }

but this gives the same result for keys that have neven been touched and those that have been assigned the value 0 (e.g. both $hash{b} and $hash{c} evaluate as ‘false’). Is there a way of telling the difference between those two ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T19:23:32+00:00Added an answer on May 24, 2026 at 7:23 pm

    Use the defined operator to check if something has value which is not undef

    if ( defined $hash{ $key } ) {
      //do stuff
    }
    

    Use the exists operator to check if a $key of a %hash has been written to

    if ( exists $hash{ $key } ) {
      //do stuff
    }
    

    The difference being that defined checks to see if a value is of anything other than undef and exists is used to verify if $key is a key of the hash despite its value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Is there any way to kill a Thread in Python? So this
I am wondering if there is a correct way to implement the anchor tag
Is there a leak in this C code? Although the answer is coming correct,
What do you think? Is this correct or are there memory leaks? Source: #include
HI there I was wondering if there is a better way of testing that
when using OnRender to draw something on the screen, is there any way to
Is there a way of testing functions inside a class in an easy way
Firstly I know that there are many question and solutions to correct thread marshalling
in my page there are few hidden field which are filled with the correct
Any phone numbers that begin with these ranges correct: ex: 772123322 The length is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.