読者です 読者をやめる 読者になる 読者になる

Perl日記

PerlとかRubyとかPHPとかPythonとか

undefが入ったときの組み込み関数挙動まとめ2

前回「undefが入ったときの組み込み関数挙動まとめ1 - Perl日記」の続き。

Regular expressions and pattern matching

undef =~ m|undef|
Use of uninitialized value in pattern match (m//) at ./m.pl line 5.
undef =~ s/undef/undef/e
Modification of a read-only value attempted at ./s.pl line 5.
quotemeta(undef)
Use of uninitialized value in quotemeta at ./quotemeta.pl line 5.
qr(undef)
(?-xism:undef)

当たり前だけど文字列扱い。

Functions for list data

join(undef, undef, undef)
Use of uninitialized value in join or string at ./join.pl line 5.
Use of uninitialized value in join or string at ./join.pl line 5.
Use of uninitialized value in join or string at ./join.pl line 5.
reverse(undef)

あ、警告が出ない。
undefが入ってる配列に対応させるためか。

reverse(undef, undef)
Use of uninitialized value in reverse at ./reverse.pl line 5.
Use of uninitialized value in reverse at ./reverse.pl line 5.

と思ったら、二つ入れたら警告が出た。比較対象ができちゃったからかな。

sort(undef)

ここは、$iを@iにした。

Use of uninitialized value in sort at ./sort.pl line 5.
Use of uninitialized value in print at ./sort.pl line 6.

sort()は比較対象がなくても警告が出るなあ。
よく分からない。

sort(undef, undef)
Use of uninitialized value in sort at ./sort.pl line 5.
Use of uninitialized value in sort at ./sort.pl line 5.
Use of uninitialized value in sort at ./sort.pl line 5.
Use of uninitialized value in sort at ./sort.pl line 5.
Use of uninitialized value in print at ./sort.pl line 6.
Use of uninitialized value in print at ./sort.pl line 6.

Keywords related to scoping

my(undef)
Use of uninitialized value in print at ./my.pl line 6.

あ、myも一応undef引き取ってくれるんだ。
意味無いけど。

package undef
% cat package.pl
#!/usr/bin/perl
use strict;
use warnings;

package undef;
% ./package.pl
%

"undef"という名前空間。ややこしさレベル高い。

Keywords related to classes and object-orientation

bless(undef)
Can't bless non-reference value at ./bless.pl line 5.
ref(undef)

tied(undef)
Use of uninitialized value in print at ./tied.pl line 6.

Time-related functions

time(undef)
syntax error at ./time.pl line 5, near "(undef"
Execution of ./time.pl aborted due to compilation errors.
times(undef)
syntax error at ./times.pl line 5, near "(undef"
Execution of ./times.pl aborted due to compilation errors.

timeとtimesって引数とれないんだ。

localtime(undef)
Use of uninitialized value in localtime at ./localtime.pl line 5.
Thu Jan  1 09:00:00 1970
gmtime(undef)
Use of uninitialized value in gmtime at ./gmtime.pl line 5.
Thu Jan  1 00:00:00 1970

UNIX epoch。


うーんやっぱりだいたい予想通りといったところかな。