develooper Front page | perl.perl5.porters | Postings from May 2018

Re: [perl #90240] keys(@array) gives too many indices

Thread Previous
From:
Eric Brine
Date:
May 12, 2018 02:20
Subject:
Re: [perl #90240] keys(@array) gives too many indices
Message ID:
CALJW-qHpwChaFWy0cEqdLaTV08hpNnZpuR3zi_jv8mnP4+_qsg@mail.gmail.com
On Tue, Dec 12, 2017 at 1:56 AM, Zefram <zefram@fysh.org> wrote:

> keys(@array) has a defined meaning that is consistent with the
> array-as-unbroken-sequence model that is used in most places.  To change
> it to implement the equivalent operation for the sparse-array model
> would be disruptive.  We shouldn't do that.  If you really like the
> discouraged sparse arrays and want a key-listing operation for them, you
> should implement that as an XS module and put it on CPAN.  This ticket
> should be closed.
>

Don't even need XS.

sub initialized_array_indexes(\@) {
   my $array = shift;
   grep { exists($array[$_]) } 0..$#$array
}

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About