in reply to Testing for a string value within an array

I know that I could probably use a hash instead, but don't want to use a hash

The only time a hash is not acceptible for something like this, is when you want to maintain the original insertion order. If you don't, then follow tlm's advice and use that.

If, however, you need to maintain the original order, the easiest solution is to use both a hash and an array. You may be thinking, "this sounds like a real pain." But it's not. Here's a demonstration:

my %mountpoints; my @mountpoints; for (qw(foo bar bar foo baz)) { push @mountpoints, $_ unless $mountpoints{$_}++; }

Replies are listed 'Best First'.
Re^2: Testing for a string value within an array
by state-o-dis-array (Hermit) on May 03, 2005 at 22:56 UTC
    If you need to keep the original order, is there any overhead to using Tie:LLHash over using the array? I'm guessing that Tie::LLHash must be using an array, but just provides an interface to work with only the hash?
      is there any overhead to using Tie:LLHash over using the array?

      It depends on what you mean by "overhead". Certainly, there's overhead involved in loading a module. There's overhead involved in installing a module. Depending on how the module is implemented, there's likely overhead involved in using the module. Whether that overhead is worth it or not depends on a lot of factors. But personally, I would stick with a plain dual hash/array approach unless there was a specific reason not to.