On Jun 5, Jamie Krasnoo said:

>From: Peter Scott [mailto:[EMAIL PROTECTED]]
>>
>>{ my %temp;
>>   @temp{@array} = ();
>>   @youwant = keys %temp;
>>}
>>
>>However, that said, 99 times out of a hundred you should have been keeping
>>your data in a hash to begin with and you've made a design error by putting
>>it in an array.  Also, the above method doesn't preserve the order.
>
>using Tie::IxHash would though.

Except that Tie::IxHash does far too much work such a simple task as
removing duplicates from a list.  If you understand what Tie::IxHash does,
you would never suggest it for such a situation.

If order needs to be preserved, a simple grep() (a la the FAQ) will do:

  # from perlfaq4, #38
  undef %saw;
  @out = grep(!$saw{$_}++, @in);

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
Eruséro Marillion -- wielder of Ringril, known as Hesinaur, the Winter-Sun
Are you a Monk?  http://www.perlmonks.com/     http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc.     http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter.         Brother #734
**      Manning Publications, Co, is publishing my Perl Regex book      **

Reply via email to