This tutorial walk you through multiple inbuilt functions
- defined function
- undef function
How to check variable has a value
Sometimes, We need to check variable contains an value of string or number.
defined
function checks variable has string or numeric value.
It returns 1 if variable holds some value, else return empty.
Syntax:
defined variable
Here is an Perl Defined Function example
sub isVariableHasValue {
my $value = $_[0];
if (defined $value) {
print "varible is initialized \n";
} else {
print "varible is not initialized \n";
}
}
$name = "abc";
isVariableHasValue($name);
$name1;
isVariableHasValue($name1)