Using multi-line commenting in Perl to inactivate blocks of code during testing
Published on 26th December 2019 Estimated Reading Time: 1 minuteRecently, I needed to inactivate blocks of code in a Perl script while doing some testing. Since this is something that I often do in other computing languages, I sought the same in Perl. To accomplish that, I need to use the POD methodology. This meant enclosing the code as follows.
=start
<< Code to be inactivated by inclusion in a comment >>
=cut
While the =start
line could use any word after the equality sign, it seems that =cut
is required to close the multi-line comment. If this was actual programming documentation, then the comment block should include some meaningful text for use with perldoc
. However, that was not a concern here because the commenting statements would be removed afterwards anyway. It also is good practice not to leave commented code in a production script or program to avoid any later confusion.
In my case, this facility allowed me to isolate the code that I had to alter and test before putting everything back as needed. It also saved time since I did not need to individually comment out every executable line because multiple lines could be inactivated at a time.