Perl | defined() Function Last Updated : 21 Feb, 2019 Comments Improve Suggest changes Like Article Like Report 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 or reference of a function, then it returns true if the function has been defined else it will return false if the function doesn't exist. If a hash element is specified, it returns true if the corresponding value has been defined, but it doesn't check for the existence of the key in the hash Syntax: defined(VAR) Parameters: VAR which is to be checked Returns: Returns 0 if VAR is undef and 1 if VAR contains a value Example 1: Perl #!/usr/bin/perl # Defining a variable $X = "X is defined"; # Checking for existence of $X # with defined() function if(defined($X)) { print "$X\n"; } # Checking for existence of $Y # with defined() function if(defined($Y)) { print "Y is also defined\n"; } else { print "Y is not defined\n"; } Output: X is defined Y is not defined Example 2: Perl #!/usr/bin/perl # Defining a function sub X { # Defining a variable $VAR = 20; } # Checking for existence of $X # with defined() function if(defined(X)) { print "Function Exists\n"; } # Checking for existence of $Y # with defined() function if(defined($Y)) { print "Y is also defined\n"; } else { print "Y is not defined\n"; } Output: Function Exists Y is not defined Comment More infoAdvertise with us Next Article Perl | defined() Function C Code_Mech Follow Improve Article Tags : Perl Perl-function Similar Reads Perl | exists() Function 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 2 min read Perl | each() Function This function returns a Two-element list consisting of the key and value pair for the next element of a hash when called in List context, so that you can iterate over it. Whereas it returns only the key for the next element of the hash when called in scalar context. Syntax: each MY_HASH Parameter: M 1 min read Perl | File I/O Functions File handling in Perl is used to read data from an external file or to write data into an external file. This is very useful as it provides a platform to permanently store and retrieve data from files. File Handle A FileHandle associates a name to an external file, that can be used until the end of 4 min read Perl | undef and the defined function undef is used for those variables which do not have any assigned value. One can compare it with NULL(in Java, PHP etc.) and Nil(in Ruby). So basically when the programmer will declare a scalar variable and don't assign a value to it then variable is supposed to be contain undef value. In Perl, if th 3 min read Perl | abs() function This function returns the absolute value of its argument. If a pure integer value is passed then it will return it as it is, but if a string is passed then it will return zero. If VALUE is omitted then it uses $_ Syntax: abs(VALUE) Parameter: VALUE: It is a required number which can be either positi 2 min read Like