1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Perl初学者】Perlの真偽値について

Posted at

最初に

Perlには真偽値(ブール型)というのが無い。
Perlにおける「偽」と評価される値

数値

数値
0.00 0でも偽となる
0e2 0*10の2乗のこと
0*0 答えが0になるもの

文字列

""(空文字列), "0"

未定義値

  • my;

    • my;などで宣言だけをして代入をしなかった(初期化をしていない)またはundefを使用して未定義にされた変数のこと。
  • undefを含む、返り値を返さないでサブルーチンの評価結果

「未定義値」とは

変数の中が何も入っていない値のこと。何も入っていない値なので一応値として判別されるらしい。
==eqは使えない。(だがundefが入った変数==数値0でIF文を使い比較した場合、通ってしまったので一応報告していく)

ついでに

Perlは普通のオブジェクト指向とはすこしちがった性質がある
一般的なオブジェクト指向だと$x = "1" + "2";だとエラーになるがPerlだとこれは文字列の数字同士を足してしまう。
これはPerlの性質で式の2項演算子(+のこと)が両辺のデータの形を決定するらしい。目から鱗。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?