How would you do a match and replace for multiples in a variable?
Example:
PATH=$PATH:/home/userx:/usr/X11:.:/usr/sbin:..:/usr::/var:.
I need to remove any . and .. and :: in the path and also if any of those 3 characters are at the end of the line they need to be removed.
My code works to remove the . and .. and the first instance of :: but not any subsequent instances. Also cannot get the end of line match/replace to work.
Example:
PATH=$PATH:/home/userx:/usr/X11:.:/usr/sbin:..:/usr::/var:.
I need to remove any . and .. and :: in the path and also if any of those 3 characters are at the end of the line they need to be removed.
My code works to remove the . and .. and the first instance of :: but not any subsequent instances. Also cannot get the end of line match/replace to work.
Code:
while (<>) {
chomp ($_);
if ($_ =~ m/^PATH/) {
s/\.//;
s/\.\.//;
s/::/:/;
print;
}
}