Hello Jeroen. Jeroen Lodewijks wrote: > Hi all, > > Is there anybody out there who has a code snippet to test if a list > is empty? (a list is empty if all elements are either undefined or 0 > or have an empty string) > > Ofcourse I can do this: > > my $str = ''; > my $elem; > > my (@test) = (undef, ''); #put any test data here > foreach $elem (@test) { > $str .= $elem; > } > > if ($str) { > print "not empty\n"; > } > else { > print "empty \n"; > } > > > But somehow I think there is a more clever or shorter way. > > Is there?
You can do the equivalent to your code with: $str = do { local $"; "@test" }; but this doesn't cater for elements equal to '0'. Using grep() is probably faster anyway. HTH, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]