in reply to Re: Re^4: Set Operators
in thread Set Operators
Obviously, as this task is exactly what grep was made for. :-) Although there is some Perl construct involved - the callback you have to provide to grep.
Remember that you have to iterate once over the array at least once - whatever you do. grep does nothing more than iterate - where the hash methods have to do a lot more work.
This doesn't mean grep is the be-all end-all solution: if you need to check many values against the same set, then constructing the hash will quickly pay off as all subsequent lookups run in nearly constant time. Esp when the set is large and even more so when the values are typically absent more often than not, the overhead of building the hash will pay off rapidly.
Efficiency can only be achieved with knowledge of an algorithm's expected input data.
Makeshifts last the longest.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re^6: Set Operators
by Notromda (Pilgrim) on Oct 28, 2002 at 21:18 UTC |