On Jan 2, 2004, at 10:18 AM, Jeff Westman wrote:

What is the proper way to test if an array is empty ?

Probably the easiest is:


if (@array) {
        # not empty
}
else {
        # empty
}

# or...

unless (@array) {
        # empty
}

This works because an array in scalar context returns the number of elements it contains. If it contains 0, that will equate to false. Anything else will be true.

James


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to