Comments

Study what comments are and how we should write them.

We need to add comments in our code to make it more readable for the reader. Comments in Perl are of two types:

  • Single line comment
  • Multiline comment

Single line comment

If our comment can fit on a single line, then we can use a # symbol.

Press + to interact
# this is a single line comment
print "Hello World"; # This line prints Hello World

Explanation

We use the # symbol for a single line comment. We can use multiple instances of # symbols in our code to comment on multiple single lines.

Multiline comment

If there is a paragraph or functionality which takes more than one line explanation then we can use a multiline comment which starts with = (followed by some text ) and ends with =cut.

Press + to interact
=POD
this
is a
multiline
comment
=cut

Explanation

A multiline comment starts with =(text) sign and ends with =cut keyword. You can write anything between these lines and it will not be executed.

It is a common convention to start a multiline comment with =POD and end at =cut