All pastes #17264 Raw Edit

Kevin

public text v1 · immutable
#17264 ·published 2005-07-08 23:07 UTC
rendered paste body
my $foo = [ 'a', ['b', 'c', [ 'd' ]] ];

print counter($foo);

sub counter
{
    my $foo = shift;

    my $count = 0;

    foreach (@$foo) {
        if (ref($_) eq 'ARRAY') {
            $count += counter($_);
        }
        else {
            $count++;
        }
    }
    return $count;
}