Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re^5: "undef" is not NULL and what to do about it

by salva (Abbot)
on Feb 21, 2013 at 15:58 UTC ( #1019972=note: print w/ replies, xml ) Need Help??

in reply to Re^4: "undef" is not NULL and what to do about it
in thread "undef" is not NULL and what to do about it

It occurs to me that there is another way to attack this problem, because, well, as you say in your post, you don't want the app to die after several hours just because some unknown value has slipped in.

My idea is to imitate the taint approach. In the place where data is generated (i.e., DBI) it is flagged as maybe_unknown, then when it is used in other parts of the program the app will croak unless the flag had been removed with some check as is_unknown.

Also, this feature should be easyly disabled, so that it can be used in development but turned off in production environments. For instance:

sub data_generator { return maybe_unknown(@real_data); # attach maybe_unknown flag } sub data_processor { for my $data (@_) { if ($data =~ /foo/) { # in development this line croaks # because $data may be unknown. # Note that it will croak even when $data # is not actually 'unknown'! ... } unless (is_unknown($data)) { # clears the maybe_unknown flag if ($data =~ /foo/) { # does not croak because the maybe_unknown # flag has already been removed from $data ... } } } sub main { data_processor(data_generator); }
Comment on Re^5: "undef" is not NULL and what to do about it
Select or Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2016-05-30 19:57 GMT
Find Nodes?
    Voting Booth?