undef

How can you get Perl to stop when referencing an undef value?

How do you get Perl to stop and give a stack trace when you reference an undef value, rather than merely warning? It seems that use strict; isn't sufficient for this purpose. ...

Check for value definedness in C++

Hello, I'm working in C++ and I need to know if a scalar value (for instance a double) is "defined" or not. I also need to be able to "undef" it if needed: class Foo { public: double get_bar(); private: double bar; void calculate_bar() { bar = something(); } }; double Foo::get_bar() { if ( undefined(bar) ) ...

How can I render undefined values from printf in Perl?

I'm looking for an elegant way to denote undefined values in situations where formatted numbers usually render. I'll work up a small example. For starters, you of course can't use this: #!/usr/bin/perl use strict; use warnings; for my $s (1, 1.2, undef, 1.3) { printf "%5.2f\n", $s; } ...because the 'use warnings' nails you with 'U...

How can I print a literal 'null' for undefined values in Perl?

I am running a query 'describe table' and it returns value of 'null' for the 'default' column. However, when I try to print the value from database to an HTML table it is not printing 'null'. It is just always blank. This is how I am storing the data from database: @nulls = (); while (($null) = $sth1->fetchrow_array) { push...

Why is 'undef' not detected by this Perl fragment?

I would expect the block in the second 'if' statement to be entered because of the undef value but the logs show that it isn't being entered. sub getcmd{ my $self = $_[0]; if ( $self->_recv == OK ){ push @{$self->{'log'}}, ['NOTICE', "OK"]; return "My command"; } push @{$self->{'log'}}, ['ERROR', "Did not g...

In Perl, is there graceful way to convert undef to 0 manually?

I have a fragment in this form: my $a = $some_href->{$code}{'A'}; # a number or undef my $b = $some_href->{$code}{'B'}; # a number or undef $a = 0 unless defined($a); $b = 0 unless defined($b); my $total = $a + $b; The reality is even more messy, since more than two variables are concerned. What I really want to write is this: my $t...

Assigning multiple values in perl, trouble with undef

I want to return several values from a perl subroutine and assign them in bulk. This works some of the time, but not when one of the values is undef: sub return_many { my $val = 'hmm'; my $otherval = 'zap'; #$otherval = undef; my @arr = ( 'a1', 'a2' ); return ( $val, $otherval, @arr ); } my ($val, $otherval, @arr) ...

Good way to document #undef in doxygen

I currently have a couple of #define in c files that turn off some functionality to hardware for testing. However, I want to document them with doxygen when they are undefined as well. For example: This works fine: /// \def SIMULATE_SOME_HW_INTERFACE /// Define this when you want to simulate HW interface. #define SIMULATE_SOME_HW_INTE...