in reply to Re^2: RFC: newscript.pl , my very first script!
in thread RFC: newscript.pl , my very first script!

Darfoune:

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

    I can see now how more easy it would be with a heredoc having bigger headers ..!

    About the tags for cluster of frequently used modules, I will look for a way so that the user would input it's prefered module and cluster them. I use so very few modules myself right now that I wouldn't know which ones to group together. I will post it as soon as I have a working version