in reply to Re^2: Check if array is null
in thread Check if array is null

ikegami,
Your first and second are identical in function

Not according to my test:

#!/usr/bin/perl use strict; use warnings; my @array = (undef, undef); print "foo\n" if defined @array; print "bar\n" if grep defined , @array; __END__ $ perl foo.pl defined(@array) is deprecated at foo.pl line 5. (Maybe you should just omit the defined()?) foo $ perl -v This is perl, v5.8.5 built for cygwin-thread-multi-64int

Cheers - L~R

Replies are listed 'Best First'.
Re^4: Check if array is null
by ikegami (Patriarch) on Oct 06, 2004 at 16:49 UTC
    Read again. I said the first and second are the same, not the first and third. Your snippet even supports me because it says defined shouldn't be used on arrays.
      ikegami,
      Ok - so I can't read ;-) I still get conflicting results:
      #!/usr/bin/perl use strict; use warnings; my @array = (undef, undef); pop @array; pop @array; print "foo\n" if defined @array; __END__ defined(@array) is deprecated at foo.pl line 7. (Maybe you should just omit the defined()?) foo

      Cheers - L~R

        That's interesting! It seems defined returns true if there once was data in the array.

        my @array = (); print defined(@array)?1:0, $/; # 0 print scalar(@array)?1:0, $/; # 0 push(@array, 'bla'); pop(@array); print defined(@array)?1:0, $/; # 1 print scalar(@array)?1:0, $/; # 0 undef(@array); print defined(@array)?1:0, $/; # 0 print scalar(@array)?1:0, $/; # 0