Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^2: Perl one-liner to remove duplicate entries from PATH

by sfink (Deacon)
on Jan 12, 2006 at 18:09 UTC ( [id://522769]=note: print w/replies, xml ) Need Help??


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

Or a variant using colon-terminated lines rather than colon-separated fields, allowing the uniqueness code itself to be very straightforward:
MYPATH=$(echo -n "$PATH"|perl -072 -lne 'print unless $s{$_}++')
(octal 072 is ":", the colon character)

Because this is interpreting the entries in $PATH as colon-terminated rather than colon-separated, though, this will tack on an unwanted colon at the end.

So the full solution wouldn't be as pretty. You'd need something like:

MYPATH=$(echo -n "$PATH"|perl -072 -lne 'print unless $s{$_}++') MYPATH="${MYPATH%:}"

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://522769]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-25 23:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found