I am writing a Perl script where I read files containing section Perl code and non Perl data.
After processing the files I write them to a temporary files (generated scripts) which is then executed using an eval
command. I don't want to run the generated script separately as I need to use the variables in the main script to be interpolated in the generated scripts.
I need to redirect the output of the eval command to a file. Any suggestion on how to achieve this?
Steps in the script:
READ_FILE
Process file
Write back with temp file name
Read temp file (my $file_name = read_file('temp_file_name')
)
eval (eval $file_name
)
Appreciate the help.
This can be done without any additional modules
use strict;
use warnings;
open my $fh, '>', 'foo.txt' or die $!;
my $old_fh = select $fh;
eval q{ print "Hello World!\n"; };
select $old_fh;