in reply to Do I need to use defined?

Yes. The second one will print when $test is 0, but the first one won't.

Replies are listed 'Best First'.
Re^2: Do I need to use defined?
by IruP (Initiate) on Sep 07, 2017 at 05:57 UTC
    can you describe why?

      Uh ... because 0 is defined.

      ...roboticus

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

      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". ;-)