counting number of empty strings in a multidimensional array column

Discussion in 'Perl Misc' started by Jack, Jul 29, 2006.

  1. Jack

    Jack Guest

    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;
    }
    Jack, Jul 29, 2006
    #1
    1. Advertising

  2. Jack

    Mumia W. Guest

    Re: counting number of empty strings in a multidimensional arraycolumn

    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;
    }
    Mumia W., Jul 29, 2006
    #2
    1. Advertising

  3. Jack

    -berlin.de Guest

    Re: counting number of empty strings in a multidimensional arraycolumn

    Mumia W. <> 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
    -berlin.de, Jul 30, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ranjmis
    Replies:
    14
    Views:
    512
    Ben C
    Mar 12, 2006
  2. Wybo Dekker
    Replies:
    1
    Views:
    167
    Charles Steinman
    Jul 23, 2005
  3. Gunnar Hjalmarsson
    Replies:
    8
    Views:
    183
    Paul Lalli
    Jun 10, 2004
  4. Jack
    Replies:
    22
    Views:
    245
    Ted Zlatanov
    Aug 10, 2006
  5. edwardfredriks

    counting up instead of counting down

    edwardfredriks, Sep 6, 2005, in forum: Javascript
    Replies:
    6
    Views:
    182
    Dr John Stockton
    Sep 7, 2005
Loading...

Share This Page