Add -r (--reverse) option.

This commit is contained in:
Peter J. Holzer 2018-09-13 19:05:06 +02:00
parent e27477085c
commit 59e958e160
1 changed files with 12 additions and 0 deletions

View File

@ -38,6 +38,12 @@ Print a complete variable assignment statement ready to be eval'd by a
POSIX shell. Unlike the C<-e> option this does not prepend the export POSIX shell. Unlike the C<-e> option this does not prepend the export
keyword, so the variable is private unless it is exported elsewhere. keyword, so the variable is private unless it is exported elsewhere.
=item B<-r>
Reverse order of arguments. This is useful if you have several versions
of a software installed and you want the one with the highest version
number first in your path.
=back =back
=head1 AUTHOR =head1 AUTHOR
@ -54,11 +60,13 @@ my $debug;
my $var = 'PATH'; my $var = 'PATH';
my $export; my $export;
my $private; my $private;
my $reverse;
GetOptions("check" => \$check, GetOptions("check" => \$check,
"debug" => \$debug, "debug" => \$debug,
"var=s" => \$var, "var=s" => \$var,
"export" => \$export, "export" => \$export,
"private" => \$private, "private" => \$private,
"reverse" => \$reverse,
) or do { ) or do {
require Pod::Usage; require Pod::Usage;
import Pod::Usage; import Pod::Usage;
@ -72,6 +80,10 @@ if ($#ARGV == 0 && $ARGV[0] =~ /:/) {
@ARGV = split(/:/, $ARGV[0]); @ARGV = split(/:/, $ARGV[0]);
} }
if ($reverse) {
@ARGV = reverse @ARGV;
}
my %seen; my %seen;
my @newpath; my @newpath;