in reply to Re: To test empty array in perl
in thread To test empty array in perl

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re^3: To test empty array in perl
by Fletch (Bishop) on Apr 26, 2010 at 16:03 UTC

    Using defined on an aggregate's been out of fashion for a good while now.

    $ perl -e 'use strict;use warnings;my @foo;if( defined @foo ) { print +"foo" }' |& splain defined(@array) is deprecated at -e line 1 (#1) (D deprecated) defined() is not usually useful on arrays because i +t checks for an undefined scalar value. If you want to see if the array is empty, just use if (@array) { # not empty } for example. (Maybe you should just omit the defined()?)

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

      And even before it went out of fashion, it never was the correct test whether it contained elements anyway. An array could be defined, yet empty - although it being undefined implied it being empty.