On 07/29/2006 10:03 AM, Jack wrote:
> Hi some folks helped me with uniques in this context, but this is a
> different beast..
> trying to count the number of empty strings in a multidimensional array
> column without creating too much memory overhead since I need to do
> this for each column (and I dont want to create a new array just for
> that column).. so I tried the below which is a similar approach to what
> some experts on this site suggested for uniques, but didnt lend itself
> to evaluating each value in the array as you will see in the code
> below, any ideas would be appreciated -
> Many thanks,
> Jack
>
> $nullcount= nulls(map { $_->[$p] } @multiarray);
> push @nullcounts, $count;
> $nullcount=0;
>
> sub nulls
> {
> my %nulls = ();
> if (/^\z/)) { $nulls{$1}++ foreach @_}
> return keys %nulls;
> }
>
This should count the number of empty strings in a column:
sub countNulls {
no warnings 'uninitialized';
my ($arref, $col) = @_;
my $count = 0;
$_->[$col] =~ /^\z/ && $count++ for (@$arref);
$count;
}
|