Keep It Simple, Stupid | |
PerlMonks |
Re: Yet another config file editing programme : Tell me how to make it better !by eyepopslikeamosquito (Archbishop) |
on Sep 02, 2021 at 13:37 UTC ( [id://11136368]=note: print w/replies, xml ) | Need Help?? |
What slapped me in the face the instant I saw your script is:
While this style of programming may work for small throw away scripts, it does not scale over time. As your program suite grows over time, you'll want to put utility subroutines into modules, along with unit tests, so the code can be understood in isolation, tested in isolation, and reused by multiple scripts. For that to work, you must avoid global variables. Instead, each subroutine must have well-defined inputs and outputs. To illustrate, here's a sample subroutine to read your input file along with an illustrative trivial main program that calls it:
Note that this subroutine does not use any global variables, just reads the specified input file and returns a reference to a hash of properties ... so could be easily put into a module and reused by many different main programs in your suite. A couple of related points from On Coding Standards and Code Reviews:
In Section
Seekers of Perl Wisdom
|
|