Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > counting number of empty strings in a multidimensional array column

Reply
Thread Tools

counting number of empty strings in a multidimensional array column

 
 
Jack
Guest
Posts: n/a
 
      07-29-2006
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;
}

 
Reply With Quote
 
 
 
 
Mumia W.
Guest
Posts: n/a
 
      07-29-2006
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;
}

 
Reply With Quote
 
 
 
 
anno4000@radom.zrz.tu-berlin.de
Guest
Posts: n/a
 
      07-30-2006
Mumia W. <mumia.w.18.spam+> wrote in comp.lang.perl.misc:
> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
counting number of uniques in a multidimensional array column Jack Perl Misc 22 08-10-2006 06:25 PM
Counting number of strings literals in double dimentional char array ranjmis C Programming 14 03-12-2006 11:51 PM
counting up instead of counting down edwardfredriks Javascript 6 09-07-2005 03:30 PM
RAILS: edit turns null strings into empty strings Wybo Dekker Ruby 1 07-23-2005 05:30 PM
best way to count the number of rows in a multidimensional array Jack Perl Misc 8 06-10-2004 07:31 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57