Below is a simple perl script which explains how to find if any given variable is defined or not.
Feel free to copy and use this code.
Feel free to copy and use this code.
Source
: cat undefined.pl
#!/usr/bin/perl
use strict;
use warnings;
my $Undefined;
my $Defined = "linuxpoison";
print "The value of Undefined is ", defined $Undefined, "\n";
print "The value of Defined is ", defined $Defined, "\n";
print "------------------------------\n";
$Undefined = $Defined;
$Defined = undef;
print "The value of Undefined is ", defined $Undefined, "\n";
print "The value of Defined is ", defined $Defined, "\n";
Output: perl undefined.pl
The value of Undefined is
The value of Defined is 1
------------------------------
The value of Undefined is 1
The value of Defined is
: cat undefined.pl
#!/usr/bin/perl
use strict;
use warnings;
my $Undefined;
my $Defined = "linuxpoison";
print "The value of Undefined is ", defined $Undefined, "\n";
print "The value of Defined is ", defined $Defined, "\n";
print "------------------------------\n";
$Undefined = $Defined;
$Defined = undef;
print "The value of Undefined is ", defined $Undefined, "\n";
print "The value of Defined is ", defined $Defined, "\n";
Output: perl undefined.pl
The value of Undefined is
The value of Defined is 1
------------------------------
The value of Undefined is 1
The value of Defined is
source:http://linuxpoison.blogspot.com/2012/08/13578167758219.html