Charles K. Clarkson wrote: > Mr. Shawn H. Corey wrote: > > : OK, here's a solution that might be faster. The problem with > : it is as_array() which has to scan the list every time. There > : is not simpler way for it to work. > > We could do a unique check only when the array is accessed > instead of every time a value is added. Then we used the cached > result until another element is added. > > use strict; > use warnings; > > use Tie::Array::Unique; > (rest of message deleted)
The problem with this module is that both its version of push() and unshift() do not add elements if they are already in the array. That means the array will not keep the order of most recent to oldest. It could also mean that the most-recent element may be dropped when the list is pruned to $maximum elements. In order to keep the array in order of most recent to oldest, you either have to: * Scan the array every time you add an element and remove it if found. or * Find a way to keep track of where every element is and pluck it out of the array if it's a duplicate. The former method is good if you are reading the array more often than you are adding elements. The latter is good if you are adding elements more often than reading the array. -- __END__ Just my 0.00000002 million dollars worth, --- Shawn "For the things we have to learn before we can do them, we learn by doing them." Aristotle * Perl tutorials at http://perlmonks.org/?node=Tutorials * A searchable perldoc is at http://perldoc.perl.org/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>