# Dies if f() returns any false value (incl, but not limited to, undefined)
my $result = f()
or die ...;
# Dies if f() returns an undefined value
defined( my $result = f() )
or die ...;
# Dies if f() returns nothing at all
my ($result) = f()
or die ...;
As you can see, my $result = f() or die ...;
will die not just for undefined values, but for all false values.
To only die when an undefined value is returned, use one of the following:
defined( my $result = f() )
or die ...;
my $result = f()
// die ...;
Note that these are subtly different. The first performs the assignment before the check, while the other performs the check before the assignment.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…