http://qs1969.pair.com?node_id=25673


in reply to undefs and functions

I think Ithe most elegant solution is the eval so far. (Thanks for the other suggestions!) But I think I will combine the results of the suggestions, and will come up with a new Class, which will be returned if an undefined or nonexistent hash key has been found. So I will do module like this:
package TableMap::Undef; use strict; use overload "0+" => sub { return undef }, "bool" = sub { return undef }; sub new{ my $a={}; my $x=shift; bltess ($a,ref($x)||$x); tie(%$a,"TableMap::Undef::TIE"); return $a; }; sub AUTOLOAD { return new TableMap::Undef; }; sub DESTROY {}; package TableMap::Undef::TIE; use strict; sub TIEHASH { my $a={}; my $x=shift; bless ($a,ref($x)||$x); return $x; }; sub FETCH { return new TableMap::Undef; };
Every time I need to return an undef I will return "new TableMap::Undef". This object is treated as undef as bool and numeric value, so this will cause right results when we test the value. This problem wuold be solved with a new perl pseudo-variable, we can call it $LAST for example, this is the value of the last similar level tag in the current expression. For example, I want to do things like this:
my $x=$s->{db} && $LAST->{users} && $LAST->{$user_id_1} && $LAST->limi +ts && $LAST->{$user_id_2};
What do you think about it? Will it be a good feature request in perl6?