Thanks Will but I'll own up to maybe not reading the spec closely 
enough. Is the string " " to be considered empty? It passes defined() 
nevertheless...as does the empty string ''. Embarrassing.

> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] Behalf Of
> Will of Thornhenge
> Sent: Wednesday, August 13, 2003 8:36 PM
> To: [EMAIL PROTECTED]
> Cc: 'David Byrne'
> Subject: Re: empty versus zero
> 
> 
> I prefer Lynn. Rickards' method to the others I've seen mentioned. 
> Testing whether the value is defined will always work quietly and 
> swiftly; several of the other tests proposed will generate warnings 
> under some conditions, which can really bog down a loop.
> 
> Lynn. Rickards wrote:
> >  
> > 
> >>I think this is a fairly simple question...
> >>How can I count empty values in an array?  This count
> >>should not include zeros or non-empty values.  Below
> >>is my current script, but it isn't working properly.
> >>
> >>I appreciate any assitance that you may provide.
> >>
> >>Thank you,
> >>David
> >>
> >>#!perl -w
> >># Count missing values
> >>while (my $line = <>) {
> >>    chomp ($line);
> >>    my ($probe_id,$expression) = split /\t/, $line, 2;
> >>    my @expression = split /\t/, $expression;
> >>    my $count = 0;
> >>    foreach my $value (@expression) {
> >>#   if (!$value) {
> >>
> > 
> > One way could be to use defined()....
> > 
> >         unless(defined($value)) $count += 1;
> > 
> >>#   }
> >>    }
> >>    print "$count\n";
> >>}
> 
> Another way, utilizing the magic "for" and "defined" do with "$_":
> 
> 
> for (@expression) { $count++ if not defined}
> print $count, "\n";
> 
> 
> So lots of different ways to do it.
> 
> 
> --
> Will Woodhull
> [EMAIL PROTECTED]
> 
> _______________________________________________
> Perl-Win32-Users mailing list
> [EMAIL PROTECTED]
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to