Removing Duplicate PATH Entries, Part II: the Rise of Perl

bash

 

With apologies to Arnold and the Terminator franchise for the title, let’s look one more time at removing duplicates from the PATH variable. This take on doing it was prompted by a comment from a reader named Shaun on the previous post that asked “if you’re willing to use a non-bash solution (AWK) to solve the problem, why not use Perl?” Shaun was kind enough to provide a Perl version of the code, which was good, since I’d have been hard-pressed to come up with one. It’s a short piece of code, shorter than the AWK version, so it seemed like it ought to be fairly easy to pick it apart. In the end, I’m not sure I’d call it easy, but it was interesting, and I thought other non-Perl programmers might find it interesting too.

Source: Linux Journal