in reply to in function?
If you use a hash instead of an array everywhere, you can also save the one-time overhead of setting up the hash in the first place. Using a hash makes the test closer to unit time than linear, which can speed things up significantly if you have a lot of array elements, or if you're doing a lot of "in"-like tests.# assume your array is still in myarray; set up a hash foreach (@myarray) { $myhash{$_} = 1; } # now, test for the existence of 'blah' if ($myhash{'blah'}) { do_something(); }
Alan
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: Re: in function?
by SuperCruncher (Pilgrim) on Jul 08, 2000 at 15:35 UTC |