Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
14
Task/Empty-string/Perl/empty-string-2.pl
Normal file
14
Task/Empty-string/Perl/empty-string-2.pl
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
$s = "";
|
||||
if ($s) { ... } # false
|
||||
|
||||
# to tell if a string is false because it's empty, or it's plain not there (undefined)
|
||||
$s = undef;
|
||||
if (defined $s) { ... } # false; would be true on ""
|
||||
|
||||
# though, perl implicitly converts between strings and numbers, so this is also false
|
||||
$s = "0";
|
||||
if ($s) { ... } # false; also false on "000", "0.0", "\x0", "0 with text", etc
|
||||
|
||||
# but a string that converts to number 0 is not always false, though:
|
||||
$s = "0 but true";
|
||||
if ($s) { ... } # it's true! black magic!
|
||||
Loading…
Add table
Add a link
Reference in a new issue