in reply to Re: Do I need to use defined?
in thread Do I need to use defined?

can you describe why?

Replies are listed 'Best First'.
Re^3: Do I need to use defined?
by roboticus (Chancellor) on Sep 07, 2017 at 06:02 UTC

    Uh ... because 0 is defined.

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

Re^3: Do I need to use defined?
by Anonymous Monk on Sep 07, 2017 at 06:19 UTC
    In Perl, three things are false: the undefined value (undef), the empty string (''), and zero (0). Two of those things are defined.

      Empty arrays and hashes are also false:

      >perl -E 'my @a=(); my @a2=@a or say "FALSE"' FALSE >perl -E 'my %h=(); my %h2=%h or say "FALSE"' FALSE >perl -E 'my @a=(0); my @a2=@a or say "FALSE"' >perl -E 'my %h=(""=>0); my %h2=%h or say "FALSE"' >

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
        Empty arrays and hashes become zero in scalar context, and zero is false.