There's always more than one way to do it :) but it looks to me like this does approximately the same thing yours does:
-
$status = system "/usr/bin/python BodyTextExtractor.py $PName.txt >$PName";
-
Of course, I know nothing about BodyTextExtractor.py and what it wants for input, what it would do with output, etc. I'm also not sure what you want to do with the $status or what values you're checking. See the perldocs for the
System function since that may be different from the Win32::Job status return values. The reference also gives some examples of how you might check those values.
In my own programs, I also normally extract system-dependent commands like
"C:\\Python24\\python.exe" or
"/usr/bin/python" into variables (essentially constants) that I define near the beginning of the perl program. It makes life easier when you have to do something like move the script to a different platform. You might want to do that while you're porting. So, e.g.:
-
$Python = '/usr/bin/python';
-
$Extractor = 'BodyTextExtractor.py';
-
....
-
$status = system "$Python $Extractor $PName.txt >$PName";
-
Of course, I also don't know what you're planning to do with the output, which it looks like you're sending to a temporary file. If you're planning to process that output futher in your own program, you might be better off using a construct like:
-
$command = "$Python $Extractor $PName.txt";
-
open IN, "$command |"
-
or die "Could not execute \"$command\": $!\n";
-
@lines = <IN>;
-
close IN;
-
Note the "pipe" symbol at the end of the command. This pipes the output of BodyTextExtractor.py directly into your (calling) perl program and you can then just collect them into an array such as @lines. You may find this a useful idiom. Or, alternatively, it may not be what you want here.
As usual, the answer is "it depends."
Best Regards,
Paul