armight29 has asked for the wisdom of the Perl Monks concerning the following question:

hello trying to create a loop which will iterate through an array of .xml files to add subtitles to a clip with spumux..but not working. Here is code:

foreach my $i(0 .. $#subxmlfiles) { chdir('/users/dragonzero29/.wine/drive_c/mvtmp') or die "Could not cha +nge to dir...$!"; my @subxmllist=glob("@subxmlfiles"); system("spumux -s$i -m dvd -P \"/users/dragonzero29/.wine/drive_c/mvtm +p/$subxmllist[$i]\" < \"/users/dragonzero29/.wine/drive_c/mvtmp/$MM.M +PG\" > \"/users/dragonzero29/.wine/drive_c/mvtmp/.\" . ++$MM . \".MPG +\""); }

The array @subxmlfiles is created earlier in the script and if you're not familiar with spumux it takes an .xml file and uses it with an input clip to create subtitles and then outputs to your designated filename; if you have multiple .xml files (for multiple languages) then

each invokation of spumux MUST use the previous muxed clip to add to...I hope this makes sense. This is where I run into problems. the first clip (without subs) should be 0.MPG. This will be the input file and it will be used with the first .xml file in the array and the output file should a filename with $MM incremented by 1 which will be 1.MPG; 1.MPG will then be the input for the next iteration of the loop and so on and so forth so your expertise will be greatly appreciated :)

Replies are listed 'Best First'.
Re: Spumux loop to add subs..
by hippo (Archbishop) on Aug 14, 2018 at 16:40 UTC

    Your increment of $MM applies to both values in the same command. Just use $i with a + 1 instead:

    #!/usr/bin/env perl use strict; use warnings; for my $i (0 .. 9) { my $j = $i + 1; print "Input $i.mpg, output $j.mpg\n"; }

    Having the chdir and the glob inside the loop is pointless as they don't appear to be changing. And please put that long path into a variable instead of repeating it four times - typos will not be kind to you otherwise. Since you've changed directory already you can probably just use relative paths anyway.

Re: Spumux loop to add subs..
by roboticus (Chancellor) on Aug 14, 2018 at 16:37 UTC

    armight29:

    It doesn't work? Why not? You tell us what it should be doing, but not what it *is* doing or failing to do.

    I'd try:

    • Use the list form of system, rather than trying to pass it a string. The string form can be problematic when you're trying to handle quoting and such. I don't know anything about spumux, so I can't make any specific recommendations, but I'd hope it would have options for passing the input and output filename on the command like. If so, you might be able to do something like:
      my $inf = "/users/dragzonzero29/.wine/drive_c/mvtmp/$MM.MPG"; ++$MM; my $outf = "/users/dragzonzero29/.wine/drive_c/mvtmp/$MM.MPG"; system("spumux", "-s$i", "-m", "dvd", "-P", "/usrs/dragonzero29/.wine/drive_c/mvtmp/$subxmllist[$i +]", "--input-file", $inf, "--output-file", $outf);
    • Try replacing "spumux" with "echo" and see what's being printed out, to verify that you're getting what you're hoping for.

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

      thank you all for your comments...very helpful :)