in reply to Re^2: Sparse arrays?
in thread Sparse arrays?

If anyone knows of a different way to go directly from real element to real element that'd really keen.

Easy-peasy:
foreach my $element (@sparse) { if ( defined $element ) { # YOUR CODE HERE # } }
defined() should be fast enough that calling it even a million times is no big deal.
--
Spring: Forces, Coiled Again!

Replies are listed 'Best First'.
Re^4: Sparse arrays?
by diotalevi (Canon) on Dec 18, 2002 at 16:52 UTC

    That is less powerful than the example I posted and gains you nothing. Three tested states are uninitialied, undefined and defined. My snippet replaces your defined() test with an exists() test which diferentiates between non-existant elements and merely undefined.

    The "different" way I was thinking of would probably use something other than for() since for() also returns uninitialized elements. It's not sparse aware. You know - something like each() for arrays.


    Fun Fun Fun in the Fluffy Chair