Perl Programming/Comments

From Wikibooks, open books for an open world
< Perl Programming
Jump to navigation Jump to search
Previous: Numbers Index Next: Conditionals

Comments[edit]

Comments should be used in your Perl script to help other developers who may look at your project later down the line understand what it is you have done. A comment can be made using the # key.

Example:

#This is commented out
this is not commented out and is visible to the program meaning the program will try and interpret/compile it

In some text editors, such as sublime (link at the bottom), you can comment out large sections of code by highlighting the code and pressing ctrl+/. It doesn't matter what language you are coding in, if you have the file saved and sublime knows what file type it is, it will automatically put the right comment syntax in for you. This is useful, if you have not fully completed a function, for example and need to run/test the program. If you try running the program without commenting it out it will obviously throw an error (unless the function does do something, just not what you want it to). Commenting it out will mean that the program will not see the function and also means you don't have to delete it , meaning you can carry on right where you left off when you continue to edit. (To uncomment large sections in sublime, just highlight the text and press the same keys).

Comments are also a crucial part to declaring the file type, the authors name, the date the file was made and what it is the program is supposed to do. Developers will not respect your work unless you do this correctly and give them all the details they need. It should be written like this:

#!/bin/usr/perl
# Author: (your name)
# Date  : 2015-06-19
# Code to give an example to the wonderful Perl community on Wikibooks
Previous: Numbers Index Next: Conditionals