PyrexKidd has asked for the wisdom of the Perl Monks concerning the following question:
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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Using Templates
by jethro (Monsignor) on Oct 18, 2010 at 16:54 UTC | |
Re: Using Templates
by samtregar (Abbot) on Oct 18, 2010 at 17:12 UTC | |
Re: Using Templates
by kcott (Archbishop) on Oct 18, 2010 at 16:17 UTC | |
Re: Using Templates
by locked_user sundialsvc4 (Abbot) on Oct 18, 2010 at 19:09 UTC | |
Re: Using Templates
by Anonymous Monk on Oct 18, 2010 at 21:03 UTC |