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 | |
by revdiablo (Prior) on May 03, 2005 at 23:45 UTC |