Last active
October 20, 2020 14:37
-
-
Save worthmine/aa05d5a40cef2216afa09a17b15eaf92 to your computer and use it in GitHub Desktop.
In Perl, what is omitted precisely when you declare variables with omitting default values?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use feature qw(say); | |
say "## scalars ##"; # スカラは通る | |
say "---- omitted ----", my $empty; # 省略 | |
if ( defined $empty ) { | |
die "it's defined! You are Liar!"; | |
} else { | |
say "is's not defined"; | |
} | |
say "---- with () ----", $empty = (); # ()で宣言 | |
if ( defined $empty ) { | |
die "it's defined! You are Liar!"; | |
} else { | |
say "is's not defined"; | |
} | |
say "---- with undef ----", $empty = undef; # undefで宣言 | |
if ( defined $empty ) { | |
die "it's defined! You are Liar!"; | |
} else { | |
say "is's not defined"; | |
} | |
say "## Arrays ##"; # 配列は | |
say "---- omitted ----", my @empties; # 省略 | |
if (@empties) { | |
die "it's defined! You are Liar!"; | |
} else { | |
say "is's not defined"; | |
} | |
say "---- with () ----", @empties = (); # ()で宣言 | |
if (@empties) { | |
die "it's defined! You are Liar!"; | |
} else { | |
say "is's not defined"; | |
} | |
say "---- with undef ----", @empties = undef; # undefで宣言すると | |
# @empties = (undef); # の省略と見做されるので | |
if (@empties) { | |
die "it's defined! You are Liar!"; # ここで止まる | |
} else { | |
say "is's not defined"; | |
} | |
say "Tests passed"; | |
exit; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment