]> xenbits.xensource.com Git - libvirt.git/commitdiff
test-wrap-argv: use map and join instead of a for cycle
authorJán Tomko <jtomko@redhat.com>
Mon, 30 May 2016 16:59:42 +0000 (18:59 +0200)
committerJán Tomko <jtomko@redhat.com>
Tue, 21 Jun 2016 16:13:07 +0000 (18:13 +0200)
We have a list of parameters in @args, that need to be rewrapped
and separated by a space and escaped newline: " \\\n", with the
exception of the last one, which only needs a newline.

Instead of a for cycle, rewrap the individual arguments using map,
and interleave them with escaped newlines by using join.

tests/test-wrap-argv.pl

index 693bed558cf20e1f85b201662f23e1015b5e8039..4e942cd90fa700c5b543252015cb44f2f058bd6d 100755 (executable)
@@ -100,18 +100,10 @@ sub rewrap_line {
         }
     }
 
-    # Print env + command first
-    print join(" \\\n", @env, $cmd), " \\\n";
     # We might have to split line argument values...
-    for (my $i = 0; $i <= $#args; $i++) {
-        print &rewrap_arg($args[$i]);
-
-        if ($i != $#args) {
-            print " \\\n";
-        } else {
-            print "\n";
-        }
-    }
+    @args = map { &rewrap_arg($_) } @args;
+    # Print env + command first
+    print join(" \\\n", @env, $cmd, @args), "\n";
 }
 
 sub rewrap_arg {