Perl | exists() Function Last Updated : 07 May, 2019 Comments Improve Suggest changes Like Article Like Report The exists() function in Perl is used to check whether an element in an given array or hash exists or not. This function returns 1 if the desired element is present in the given array or hash else returns 0. Syntax: exists(Expression) Parameters: Expression : This expression is either array or hash on which exists function is to be called. Returns: 1 if the desired element is present in the given array or hash else returns 0. Example 1: This example uses exists() function over an array. Perl #!/usr/bin/perl # Initialising an array @Array = (10, 20, 30, 40, 50); # Calling the for() loop over # each element of the Array # using index of the elements for ($i = 0; $i < 10; $i++) { # Calling the exists() function # using index of the array elements # as the parameter if(exists($Array[$i])) { print "Exists\n"; } else { print "Not Exists\n" } } Output: Exists Exists Exists Exists Exists Not Exists Not Exists Not Exists Not Exists Not Exists In the above code, it can be seen that parameter of the exists() function is the index of each element of the given array and hence till index 4 (index starts from 0) it gives output as "Exists" and later gives "Not Exists" because index gets out of the array. Example 2: This example uses exists() function over a hash. Perl #!/usr/bin/perl # Initialising a Hash %Hash = (Mumbai => 1, Kolkata => 2, Delhi => 3); # Calling the exists() function if(exists($Hash{Mumbai})) { print "Exists\n"; } else { print "Not Exists\n" } # Calling the exists() function # with different parameter if(exists($Hash{patna})) { print "Exists\n"; } else { print "Not Exists\n" } Output : Exists Not Exists In the above code, exists() function takes the key of the given hash as the parameter and check whether it is present or not. Comment More infoAdvertise with us Next Article Perl | exists() Function K Kanchan_Ray Follow Improve Article Tags : Perl Perl-function Perl-Array-Functions Perl-Hash-Functions Similar Reads Perl | defined() Function Defined() in Perl returns true if the provided variable 'VAR' has a value other than the undef value, or it checks the value of $_ if VAR is not specified. This can be used with many functions to detect for the failure of operation since they return undef if there was a problem. If VAR is a function 2 min read Perl | File Test Operators File Test Operators in Perl are the logical operators which return True or False values. There are many operators in Perl that you can use to test various different aspects of a file. For example, to check for the existence of a file -e operator is used. Or, it can be checked if a file can be writte 3 min read Check if an Object of the Specified Name is Defined or not in R Programming - exists() Function exists() function in R Programming Language is used to check if an object with the names specified in the argument of the function is defined or not. It returns TRUE if the object is found.Syntax: exists(name)Parameters: name: Name of the Object to be searchedExample 1: Apply exists() Function to va 2 min read PHP | function_exists() Function The function_exists() is an inbuilt function in PHP. The function_exists() function is useful in case if we want to check whether a function() exists or not in the PHP script. It is used to check for both built-in functions as well as user-defined functions. Syntax: boolean function_exists($function 2 min read PHP method_exists() Function The method_exists() function is an inbuilt function in PHP which used to check the class method exists or not. It returns "true" if the method exists otherwise returns "false". Syntax: bool method_exists( object|string $object_or_class, string $method );Parameters: This function accepts two paramete 1 min read Like