in reply to Re^2: RFC: newscript.pl , my very first script!
in thread RFC: newscript.pl , my very first script!
While a heredoc is fixed length (barring variable substitution), you can still do multiple writes to the file. So the heredoc could have the basic header for your script. Then as the user selects other modules, you can continue to add them to the script.
open my $FH, '>', 'afile.pl'; print $FH <<EOHDR; Some header stuff EOHDR while (<>) { if (/^RPT/) { print $FH, "another line of your script" } elsif (/^FOO/) { print $FH, "something completely different" } elsif (/^Q/) { last; } }
Alternatively, you can use a heredoc to load a variable, then continue to add data to the variable:
my $SCRIPT = <<EOHDR Some header stuff EOHDR; $SCRIPT .= "More script stuff";
...roboticus
When your only tool is a hammer, all problems look like your thumb.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: RFC: newscript.pl , my very first script!
by Darfoune (Novice) on Jul 25, 2015 at 14:27 UTC |