in reply to Check if one of the array elements is not empty

Just for clarification, there is a difference between an empty string("") and a string with one space(" "):

use strict; use warnings; use 5.010; my @array=("", "jim"," "); foreach my $str (@array) { if ($str) { say "perl considers the string: -->$str<-- to be true."; }else { say "perl considers the string: -->$str<-- to be false."; } } output: perl considers the string: --><-- to be false. perl considers the string: -->jim<-- to be true. perl considers the string: --> <-- to be true.

Replies are listed 'Best First'.
Re^2: Check if one of the array elements is not empty
by desemondo (Hermit) on Nov 11, 2009 at 02:37 UTC
    Also, depending on how @array is actually populated, some elements may be undefined, which perl also treats as false, and throws a warning (if use warnings is in effect) if you try to do anything with it...

    Use of uninitialized value in concatenation (.) or string at test2.pl +line 15. perl considers the string:--><-- to be false.