parallel: Negative positional arguments (no context. No -X).

This commit is contained in:
Ole Tange 2013-02-12 21:52:01 +01:00
parent c0b620c832
commit f948768a1f
2 changed files with 9 additions and 6 deletions

View file

@ -631,7 +631,7 @@ sub get_options_from_array {
sub parse_options { sub parse_options {
# Returns: N/A # Returns: N/A
# Defaults: # Defaults:
$Global::version = 20130131; $Global::version = 20130212;
$Global::progname = 'parallel'; $Global::progname = 'parallel';
$Global::infinity = 2**31; $Global::infinity = 2**31;
$Global::debug = 0; $Global::debug = 0;
@ -4739,6 +4739,7 @@ sub simple_replace_placeholders {
# Merge arguments from records into args for easy access # Merge arguments from records into args for easy access
CORE::push @args, @$record; CORE::push @args, @$record;
} }
my $n = $#args+1;
# Which replace strings are used? # Which replace strings are used?
# {#} {} {/} {//} {.} {/.} {n} {n/} {n//} {n.} {n/.} # {#} {} {/} {//} {.} {/.} {n} {n/} {n//} {n.} {n/.}
for my $used (keys %{$self->{'replacecount'}}) { for my $used (keys %{$self->{'replacecount'}}) {
@ -4747,9 +4748,9 @@ sub simple_replace_placeholders {
# {} {/} {//} {.} {/.} # {} {/} {//} {.} {/.}
$replace{$Global::replace{$used}} = $replace{$Global::replace{$used}} =
join(" ", map { $_->replace($used) } @args); join(" ", map { $_->replace($used) } @args);
} elsif($used =~ /^\{(\d+)(|\/|\/\/|\.|\/\.)\}$/) { } elsif($used =~ /^\{(-?\d+)(|\/|\/\/|\.|\/\.)\}$/) {
# {n} {n/} {n//} {n.} {n/.} # {n} {n/} {n//} {n.} {n/.} {-n} {-n/} {-n//} {-n.} {-n/.}
my $positional = $1; # number if any my $positional = $1 > 0 ? $1 : $n+$1+1;
my $replacementfunction = "{".::undef_as_empty($2)."}"; # {} {/} {//} {.} or {/.} my $replacementfunction = "{".::undef_as_empty($2)."}"; # {} {/} {//} {.} or {/.}
# If -q then the replacementstrings will be quoted, too # If -q then the replacementstrings will be quoted, too
# {1.} -> \{1.\} # {1.} -> \{1.\}

View file

@ -129,8 +129,10 @@ echo '### --resume -k'
parallel -k --resume --joblog /tmp/joblog-resume echo job{}id\;exit 0 ::: 0 1 2 3 0 5 6 7 parallel -k --resume --joblog /tmp/joblog-resume echo job{}id\;exit 0 ::: 0 1 2 3 0 5 6 7
echo '### Negative replacement strings' echo '### Negative replacement strings'
parallel -N 6 echo {-1}orrec{1} ::: t B C D E c parallel -X -j1 -N 6 echo {-1}orrec{1} ::: t B X D E c
parallel -N 6 echo {-1}orrect ::: A B C D E c parallel -N 6 echo {-1}orrect ::: A B X D E c
parallel --colsep ' ' echo '{2} + {4} = {2} + {-1}=' '$(( {2} + {-1} ))' ::: "1 2 3 4"
parallel --colsep ' ' echo '{-3}orrect' ::: "1 c 3 4"
EOF EOF