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 | |
by poj (Abbot) on Feb 26, 2016 at 18:47 UTC | |
by Bioinfocoder (Novice) on Feb 26, 2016 at 20:32 UTC | |
by poj (Abbot) on Feb 26, 2016 at 21:09 UTC |