on-internet
← Community

Empty `vec()` is not False

Stack Overflow ·

Consider this example: #!/usr/bin/env perl my $vec0; # set the first bit of vec0 to false vec($vec0, 0, 1) = 0; print "vec0 is " . length($vec0) . " bytes long\n"; if ($vec0) { # what print "vec0 is True!\n"; } A vec used in evaluation seems to (almost) always be True - this is because a vec is really a string, and so $vec0 is a string containing "\0" which is not False according to Perl: only strings "" and "0" are False. (aside: this is False, despite being non-zero: vec($vec0, 5, 1) = 1; vec($vec0, 4, 1) = 1; because 0x30 is the ASCII code for 0) Fine: what is the "correct" way to check for

Comments

Sign in or sign up to comment and upvote.

No comments yet.