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.
In reply to Re^3: RFC: newscript.pl , my very first script!
by roboticus
in thread RFC: newscript.pl , my very first script!
by Darfoune
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |