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

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$&

Replies are listed 'Best First'.
Re^3: Perl one-liner to remove duplicate entries from PATH
by demerphq (Chancellor) on Jan 12, 2006 at 18:57 UTC
    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