IruP has asked for the wisdom of the Perl Monks concerning the following question:

2017-10-07 Note added by Athanasius: This node was copied from StackOverflow. See also Re: Extract specify values in file log using perl.


Is there any difference between these 2:

print "Undefined\n" unless defined $test;

and

print "Undefined\n" unless $test;

Replies are listed 'Best First'.
Re: Do I need to use defined?
by hippo (Archbishop) on Sep 07, 2017 at 08:03 UTC
Re: Do I need to use defined?
by Anonymous Monk on Sep 07, 2017 at 05:41 UTC
    Yes. The second one will print when $test is 0, but the first one won't.
      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.