counting number of empty strings in a multidimensional array column

J

Jack

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;
}
 
M

Mumia W.

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;
}
 
A

anno4000

Mumia W. said:
On 07/29/2006 10:03 AM, Jack wrote:
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;
}

The last three lines could be replaced by (untested)

scalar grep !length $_->[ $col], @$arref;

Anno
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top