in reply to Read in a template file, populate using user input and and generate a new file

If I've reverse engineered a spec from your post correctly, then something along these lines should suffice:

#!/usr/bin/env perl use strict; use warnings; use feature 'say'; my $infile = shift; open my $in, '<', $infile or die "Cannot open $infile: $!"; while (<$in>) { chomp; s/=\s*$/"= " . shift/e; say; } close $in;

Running it with your sample input gives:

$ ./bar.pl template.config list.txt file_list.txt ;; path to config file $;INPUT_FILE$; = list.txt ;; path to list of config files $;INPUT_FILE_LIST$; = file_list.txt ;; path to temporary directory $;TEMP_DIR$; = $;TMP_DIR$; ;; use --v for verbose summary $;OTHER_ARGS$; = --v

Update: removed a redundant mention of @ARGV in the substitution.

Update 2: for the avoidance of any confusion resulting from the parent post having been rewritten to change both the data set and the invocation, here's the original input file:

;; path to config file $;INPUT_FILE$; = ;; path to list of config files $;INPUT_FILE_LIST$; = ;; path to temporary directory $;TEMP_DIR$; = $;TMP_DIR$; ;; use --v for verbose summary $;OTHER_ARGS$; = --v

which was declared to be called as I have above and result in the output which I have also shown above.

Replies are listed 'Best First'.
Re^2: Read in a template file, populate using user input and and generate a new file
by Bioinfocoder (Novice) on Feb 26, 2016 at 16:49 UTC
    Thanks! but I just came to know that the input is little different then teh earlier post, I will try your suggestion as well!

      If you can add placeholders [% name %] to your template.config file like this

      [module1] ;;path to speedseq package binary directory $;SPEEDSEQ_BIN_DIR$; = /usr/local/packages/ ;;Sequence file 1 $;Seq1File$; = "[% seq1 %]" ;;Sequence file 2 $;Seq2File$; = "[% seq2 %]" ;;Read Group $;Read_Group$;='@RG\tID:NA12878\tSM:NA12878\tPL:ILLUMINA\tLB:NA12878\t +PU:NA12878' ;;Reference $;Reference$; = "[% ref %]" [module2] ;;Output Chromosome $;Chromosome$; = "[% chr_list %]" ;;use --v for verbose summary $;OTHER_ARGS$; = --v

      then you could use a templating module like Template::Toolkit or Template::Tiny

      poj
        Thanks a lot! This works perfect. But is there any way to populate without changing the input template file? Thanks again!