Think about Loose Coupling | |
PerlMonks |
Re: Efficient access to sparse lists?by mwp (Hermit) |
on Jan 25, 2001 at 16:47 UTC ( [id://54255]=note: print w/replies, xml ) | Need Help?? |
There are a couple options. You need to know the
index, so foreach is out. You could do
something like this:
But that is obviously inefficient, especially if your list is VERY sparse. Like with elements numbered 100, 435, 1040, etc. Why not use a hash? You can convert a sparse list to a hash like so:
And use it like this:
Other alternatives include using a pseudohash, or writing a tied array implementation that acts like a list in your code but works like a hash behind the scenes. Good luck!
In Section
Seekers of Perl Wisdom
|
|