How can I determine if a Perl hash contains a key mapping to an undefined value? -


I need to determine if any key is given to a pearl hash, but that key is of an ADFF value Will be mapped with. In particular, there is the motivation to see if a hash referencing has been given using the getopt () in the bullion flag. I have already searched both this site and Google, and is present () and define () do not apply to the position, they only see the value of someone Undefined for the given key, they do not check whether a hash is really the key if I am an RTFM here, then tell me what the manual says in the manual.

exists () and do not seem to be defined for position (), they Just see that the value is undefined for a given key, they do not see whether the key is actually the key in the hash

wrong. This is exactly what defines () , but is present () does what you want:

  my % Hash = (key1 = & gt; 'value', key2 = & amp; undefined); Moving my $ key (Qi key 1 key 2 key 3) {print "\ $ hash $ $} exists:" ($ hash {$ key} exists? "Yes": "no"). "Yes": "no"). "\ N"; print \ "hash \ $ hash {$ key} is defined:" (defined $ hash {$ key}? "" \ ". \ N";}  < / Pre> 

produces:

 $ hash {key1} exists: yes $ hash {key1} is defined: yes $ hash {key2} exists: yes $ hash {key2} defined Has been done: no $ hash {key3} exists: $ $ hash {key3} is not defined: no 

these two functions These documents are available on the command-line at perldoc -f define and perldoc -f exists (or perldoc perlfunc * for all methods Read the documentation). The official web document is here:

  • * Since you specifically mention RTFM And you probably do not know from Pearl's documentation places, let me also tell you that you do not have to go to perldoc perl or all

    Full list of perldocs Can

    Comments

    Popular posts from this blog

    oracle - The fastest way to check if some records in a database table? -

    php - multilevel menu with multilevel array -

    jQuery UI: Datepicker month format -