http://qs1969.pair.com?node_id=11136390


in reply to Yet another config file editing programme : Tell me how to make it better !

Hi OK some good feedback there. I appreciate the efforts.
Just some feedback on some of the points.
I usually write the comments first then write the code to do what the comments say. When I go back to my code long after I have forgotten what I wrote, I read my comments to figure out what is doing.
I started using Switch, then I read in CPAN "do not use if you can use given/when". Then when I used given/when, I ended up with warnings plus advice not to use given/when. Hmmmmmm. As an occasional perl user, that is a little frustrating rewriting the same section of code 3x to do exactly the same thing. I just need something that has case type functionality.
My program is running on a Raspberry Pi. There is a very small, but finite risk of the Pi being turned off in the middle of a file write. Tie::File looked like it would minimise, but not eliminate, the risk of file corruption due to power loss. I have no idea which CPAN modules are commonly, or infrequently used. How could I know??
I was actually expecting to be told that I should have used CPAN XXX module, written specifically to do the sort of thing I am doing. Editing config files is a common requirement. I know there are modules for ini files, but apparently not for the dhcpcd.conf type of file that has sections, but not really marked as such.
The major flaw with my code is the risk that one of the parameters is deleted from the config file before my code is run, causing the script to keep looking in the following sections for the missing parameter. The easiest workaround is to place the section last in the file so the search will hit EOF as the section end marker.
I accept that my code writing is far from perfect, and I will be going through my code to make improvements and corrections based on the advice received. If I haven't mentioned your feedback above, it is not because I have ignored it.
Thanks.

Dazz