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

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

Thread Previous
Eric Brine
May 12, 2018 02:20
Re: [perl #90240] keys(@array) gives too many indices
Message ID:
On Tue, Dec 12, 2017 at 1:56 AM, Zefram <> 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 Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About