I write alot of fairly small perl scripts. They will range from 10 lines to maybe 1,000 lines but the median size is probably only around 100 lines. When I start writing the script I tend to break things up into chunks and create subroutines. What happens is I end up writing alot of scripts that look something like
sub mkdir {
... directory testing logic ...
... mkdir ...
}
sub createFile {
... check for directory ...
... try and create the file, exit if failure ...
}
sub somethingElse {
.... do stuff with the file that was created ...
}
sub yetAnotherThing {
... do even more stuff ...
}
&mkdir;
&createFile;
&somethingElse
&yetAnotherThing
This has always looked very odd to me. I like that it ends up being modular and I can easily comment out certain tasks but I'm not certain it's the best way to structure such small programs.
My questions are:
- Does anyone have any specific reason why I shouldn't structure scripts in this manner? I don't see many other people doing this so it feels like perhaps I'm doing something wrong.
- Can anyone suggest a better way to structure smaller scripts? Should I just skip creating subroutines at all and write out what I want my script to do in order? Am I overthinking this? :)
Thank you!