Say I have the following Groovy code:
String name = child.getParent()?.getParent()?.getName();
Please note that it getParent()may return null, in which case the code continues to work without null pointer exception exceptions.
Is there a way to do this clearly on one line in Perl 5.8? I am ready to write a general helper method to accomplish this.
I am faced with situations where I have several nested objects and I need to do something like:
my $name = $child && $child->getParent && $child->getParent->getParent && $child->getParent->getParent->getName;
Yes, it's on one line, but IMO is poisonous.
source
share