Answer the question
In order to leave comments, you need to log in
How to pass the value of a variable in perl to an external program?
Can you please tell me how to correctly pass the value of $ word to system () for further execution in the command?
I tried options with different quotes, escaping. I can not figure it out, please tell me how the value is correctly transferred.
#!/usr/bin/perl
my $word = 'test';
#my $file = '/home/text.txt'
my @cmd = q[echo "$word" >> "/home/text.txt"];
system(@cmd);
Answer the question
In order to leave comments, you need to log in
Try like this:
#!/usr/bin/perl
my $word = 'test';
#my $file = '/home/text.txt'
my @cmd = qq(echo "$word" >> "/home/text.txt");
system(@cmd);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question