in reply to Perl one-liner to remove duplicate entries from PATH

@PATH = qw(one 1 two 2 two 2); %PATH = @PATH;
or just take a look at perldsc.


Replies are listed 'Best First'.
Re^2: Perl one-liner to remove duplicate entries from PATH
by muntfish (Chaplain) on Jan 12, 2006 at 12:21 UTC

    But the OP specified "preserving the original order of the elements". Hashes don't preserve order.


    s^^unp(;75N=&9I<V@`ack(u,^;s|\(.+\`|"$`$'\"$&\"\)"|ee;/m.+h/&&print$&
      my %path; $path{$_}=$path{$_} || 1 + keys %path for split /$sep/,$path;

      there are other more efficient ways to do that btw, im just feeling moderately cheeky. ;-)

      And for the curious you cant write that as ||= because of a bug in Perl (on some versions of Perl anyway).

      Update:

      Or maybe its not a bug. According to some the docs should be read to say that it should be valid to say

      my %path; $path{$_}||=keys %path for split /$sep/,$path;

      and some are saying that the results are undefined. sigh

      ---
      $world=~s/war/peace/g