Syntactic Confectionery Delight | |
PerlMonks |
undef is undefby jozef (Sexton) |
on Aug 29, 2012 at 08:40 UTC ( [id://990406]=perlquestion: print w/replies, xml ) | Need Help?? |
jozef has asked for the wisdom of the Perl Monks concerning the following question: Hi, mostly with DBIx::Class I have to often write: my $foo = $bar->related1->related2->foo;While any of the related objects may not exist and return undef so it's necessary to test first or do an easy bad solution and use eval: my $foo = eval{ $bar->related1->related2->foo };Which also means that when ever there is a typoo (for example misspelled relation name) inside eval {}, it's silently ignored. And here is my question: Is there a module or an easy way to say Perl that in this given scope when ever method is called on undef return undef instead of an exception? Here is how it would look like: my $foo = undef_is_undef { undef->bar };Thanks!
Back to
Seekers of Perl Wisdom
|
|