|Just another Perl shrine|
fastest way to compare two arraysby krusty (Hermit)
|on Apr 13, 2011 at 23:59 UTC||Need Help??|
krusty has asked for the
wisdom of the Perl Monks concerning the following question:
I have two arrays of numbers like so:
where the @ports array was populated from a spreadsheet and is subject to change (and the range may not be permanently fixed either). The @ports array will always be a subset of @range, though and @range will never have gaps in numbering. I'm trying to find the first open port in @ports for a given range and figure there has to be a more efficient way. What I have is a glorified increment by 1 and compare operation. I'm using 5.8 on a work server and can't upgrade to get the smart match operator.
Update: By open port, I mean port that isn't being used and therefore isn't in @ports.
I've read some of the posts and a FAQ How can I tell whether a certain element is contained in a list or array?, but none seem to quite do what I want, i.e. look for what isn't there in the most efficient manner as they all seem to do an increment by one or loop one by one, too. I thought of maybe removing indicies of a hash keyed from @range by another set of indicies from @ports instead of looping but my brain hurts now.