In many of the C and C++ files I have seen macros like this:
#ifdef X
#undef X // no statements in between
#endif
I feel that, it's adequate to simply write:
#undef X
If the macro X wasn't defined, then the #undef should have no effect.
Is it ok…
Under
use strict;
use warnings;
my $foo = undef;
the expressions
$foo . ''
and
"$foo"
both produce
Use of uninitialized value $foo in ... at ...
but the following expression gives the empty string without warning:
$foo x 1
Anyone knows why? I…
While reading from a configuration file in Perl there might be cases when a line is invalid and it does not need to get added to my array of valid lines. Since I'm using a for loop here, even the invalid lines create an undef entry. How can I remove…
How do I remove a tcl procedure?
One can
unset a variable,
override an alias with interp alias {} myproc {} otherproc,
override a proc with one defined inside another namespace with namespace import -force.
But I did not find a way to make a…
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.
This code dies as I expect it to:
use strict;
use warnings;
open my $fh, "<", "" or die $!;
But this does not:
use strict;
use warnings;
open my $fh, "<", undef or die $!;
What is going on here?
SHORT QUESTION
What are the best ways to represent true and false consistently in libraries of Perl code?
1 / 0?
1 / the special empty string that Perl's native boolean operators
return?
undef?
() (i.e. the empty list)?
QUESTION BACKGROUND
We all…
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,…
Task: to build hash using map, where keys are the elements of the given array @a, and values are the first elements of the list returned by some function f($element_of_a):
my @a = (1, 2, 3);
my %h = map {$_ => (f($_))[0]} @a;
All the okay until f()…
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() {
…
LLVM introduces the concept of "poison value", which I never feel sure to understand. For example, for the statement
%add = add nsw i32 %x, 1
If %x+1 is strictly larger than the largest i32 integer, an arbitrary value is to be assigned to %add.…
I need to hide warnings within eval but the rest of the code should continue to throw warning messages. Here is what I have -
eval "\$value = $hash->{key}";
now value of $hash->{key} could be a function call, like:
$hash->{key} =…
Please take a look at the following code:
use strict;
use warnings;
print "subroutine is defined\n" if defined &myf;
myf();
sub myf
{
print "called myf\n";
}
undef &myf;
#myf();
print "now subroutine is defined\n" if defined &myf;
The…
In my perl script, I used if ($a == undef) condition, I thought it is the same as if (not defined $a), where $a is a string as read from a csv file. However, I noticed that several string values ("", " ", "0", "-0", "+0", "@", "a", and many other…
I have a question about using #undef to redefine macros.
I have a file global.h which contains a number of #define-d macros. In the code that uses these macros, I find that the values that the macros hold are not generic enough. I want to redefine…