groovy - Perl 5.8 cascading null checks -



groovy - Perl 5.8 cascading null checks -

let's have next groovy code:

string name = child.getparent()?.getparent()?.getname();

note getparent() may homecoming null, , in case code continues work without null pointer exceptions beingness thrown.

is there way in 1 line in perl 5.8? open writing generic helper method accomplish this.

i'm running situations have several nested objects , having like:

my $name = $child && $child->getparent && $child->getparent->getparent && $child->getparent->getparent->getname;

yes in 1 line, fugly imo.

in my opinion, original groovy code on boundary of readability anyway. implement rather differently, similar look in perl be

my $name = ( $node = $node->get_parent or $node = $node->get_parent or $node->get_name );

the utility of language isn't defined ability represent complex constructs in few characters

perl groovy null

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -