in reply to Looking for exact match in an array
my %sheets; [...] # The next three methods are equivalent. Pick whichever you like most. # 1 if (not exists $sheets{$machine_sheetname}) { $sheets{$machine_sheetname} = 1; # "1" is just a dummy existenc +e flag } # 2 $sheets{$machine_sheetname} = 1 unless $sheets{$machine_sheetname}; # 3 $sheets{$machine_sheetname} ||= 1;
Then, when you need all the sheets, use this expression:
keys %sheets;
The prime limitation of this approach, however, is that hashes are not sorted. If the order of your sheets matter, this may not be appropriate after all, or, if you do want to use them, you need to use something like Tie::IxHash.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Looking for exact match in an array
by revdiablo (Prior) on Dec 10, 2004 at 17:36 UTC | |
by gaal (Parson) on Dec 10, 2004 at 20:35 UTC |