http://www.perlmonks.org?node_id=990460


in reply to undef is undef

Perhaps something like:

use feature ":5.14"; use warnings FATAL => qw(all); use strict; use Data::Dump qw(dump pp); use Test::More qw(no_plan); sub deref(@) {my $h = shift; for(@_) {return undef unless $h and ref($h) eq __PACKAGE__ and $h->can($_); $h = $h->$_; } $h } my $h = bless {a=>bless{a=>bless{a=>bless{a=>1, b=>2}}}}; sub aaa() {$_[0]->{a}} sub bbb() {$_[0]->{b}} ok !defined($h->deref(qw(bbb bbb bbb bbb))); ok 1 == $h->deref(qw(aaa aaa aaa aaa)); ok 2 == $h->deref(qw(aaa aaa aaa bbb));

Produces

ok 1
ok 2
ok 3
1..3