On Fri, 07 Mar 2003 05:53:54 -0500, 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? > Can't you use 'scalar grep($_, @test)' and do something like: print scalar grep($_, @test) ? "not " : "", "empty\n"
pete peterson -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]