Check whether a value exists before using it.

Defined Checks

defined_checks.pl
use strict;
use warnings;

my $maybe = ;
my $status = defined $maybe ? "present" : "missing";
my $value = defined $maybe ? $maybe : "fallback";

print "status=$status\n";
print "value=$value\n";
use strict;
use warnings;

my $maybe = ;
my $status = defined $maybe ? "present" : "missing";
my $value = defined $maybe ? $maybe : "fallback";

print "status=$status\n";
print "value=$value\n";
use strict;
use warnings;

my $maybe = ;
my $status = defined $maybe ? "present" : "missing";
my $value = defined $maybe ? $maybe : "fallback";

print "status=$status\n";
print "value=$value\n";
defined-check `defined` distinguishes a missing value from a present scalar.