I have a script that takes several parameters as input, via either CLI or CSV, then it takes values insets them in a template and spits them out into a new file.
Currently the way I am achieving this:
#open CSV for input
open my $CSVIN, '<', $file;
foreach (<$CSVIN>){
#split CSV into usable format
#the real script has about ten variables
(my $input1, $input2, $input3, $file_out) = split(/,/,$_);
open my $TEMPLATEIN, '<', $path_to_template;
open my $FHOUT, '>', $file_out;
foreach (<$TEMPLATEIN>){
#search and replace in the template
# where $search_pattern = arbitrary identifier
#in the template, I've been using:
#<<<Variable_1>>>
#again I have about twelve
$_ =~ s/$search_pattern1/$input1/g;
$_ =~ s/$search_pattern2/$input2/g;
$_ =~ s/$search_pattern3/$input3/g;
print $FHOUT $_;
} # end s/r from template
close($FHOUT);
close($TEMPLATEIN)
} # end iteration through CSV
I realize TIMTOWTDI, really what I am asking is what you have found to be the cleanest to read and the most efficient to run.
also any suggestions on "Best Practices" are very welcome