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? > > Cheers, > > Jeroen
#!/usr/bin/perl -w use strict; my @array = ('', 0, "", 1); my $hasTruth; foreach (@array) { if ($_ ){ $hasTruth = "yezzindeedydo!"; last; } } if ($hasTruth) {print "$hasTruth has truth\n";} else {print "Does not have truth";} Joseph -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]