Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
"be consistent"
 
PerlMonks  

Re: undef is undef

by philiprbrenan (Monk)
on Aug 29, 2012 at 13:00 UTC ( #990460=note: print w/ replies, xml ) Need Help??


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


Comment on Re: undef is undef
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://990460]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2014-04-21 08:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (492 votes), past polls