I'm writing a Perl program that must run a few Perl scripts multiple times on different inputs.
The scripts I'm trying to use are count.pl
and statistic.pl
from
Text::NSP
.
I didn't write those myself so I don't want to try and refactor them into a module.
I looked at
a similar question
and figured out how to use the system
method from
IPC::System::Simple
.
However, I want to make use of the named arguments in count.pl
and statistic.pl
. I haven't yet figured out how to do this. This is my current code:
system($^X, token="valid_tokens.txt", "/Users/cat/perl5/bin/statistic.pl", "ll.pm", "lab01_jav_bigrams.ll",
"/Users/cat/Perl_scripts/214_Final_project/lab01_java_bigrams.cnt");
And this is the error I get:
Can't modify constant item in scalar assignment at ngram_calcs.PL line 22, near ""valid_tokens.txt"," Bareword "token" not allowed while "strict subs" in use at ngram_calcs.PL line 22.
It's worth noting that the code worked fine until I added the named argument. How do I supply a named argument to IPC::System::Simple
? Or is there a better way to do what I'm trying to do?
Edit: Thanks, Haukex, I did have the wrong parameters, and using "--token=valid_tokens.txt" worked.
Even though the problem is solved, I'll share more context so that other people who see can benefit. On the commmand line I would type this:
count.pl -token validtokens.txt lab01_java_bigrams.cnt Users/cat/CS214/lab01_java.txt
statistic.pl -score 6.63 ll.pm lab01_java.ll lab01_java_bigrams.cnt
This is the correct perl code:
system($^X, "/Users/cat/perl5/bin/count.pl", "--token=valid_tokens.txt", "lab01_java_bigrams.cnt", $filename);
system($^X, "/Users/cat/perl5/bin/statistic.pl", "--score=6.63", "ll.pm", "lab01_java_bigrams.ll", "/Users/cat/Perl_scripts/214_Final_project/lab01_java_bigrams.cnt");