Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

RE: undefs and functions

by dlux (Initiate)
on Aug 02, 2000 at 11:05 UTC ( #25673=note: print w/replies, xml ) Need Help??


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?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2022-12-06 07:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?