Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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?

In reply to RE: undefs and functions by dlux
in thread undefs and functions by dlux

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found

    Notices?