Reputation: 1506
I have a perl script that always returns yesterday's date and the date is stored on a variable called $yesterday
Now, I am running that perl script using cmd prompt. After it figures out what yesterday's date was I would like to pass $yesterday somehow into the cmd line so that it can open up a "$yesterday.txt" file. The txt files are already there and match the date format in the filename.
Upvotes: 0
Views: 417
Reputation: 67910
Are you asking how to open
a file?
my $file = "$yesterday.txt";
open my $fh, "<", $file or die "Cannot open $file for reading: $!";
See the documentation for more information on the open
command.
Upvotes: 2
Reputation: 632
You can simply include the $variable in the string of the command or use string concatenation to put the static and variable parts together:
system("echo yesterday >$yesterday.txt");
or
system("echo yesterday >" . $yesterday . ".txt");
The above calls a commandline program or command from perl and the command includes the value of your $yesterday variable.
Upvotes: 1