← Back to Perl Course | Chapter 1: Introduction | Lesson 4 of 7

Comments and POD

Comments are notes for humans that Perl ignores.

In this page:

  1. Comments and POD

Comments and POD

A hash sign # starts a comment that runs to the end of the line. Perl has no block comment syntax, but POD (Plain Old Documentation) blocks can be used for longer text: a block starting with a line such as =pod or =begin comment and ending with =cut is skipped by the interpreter. POD is also the standard way to document Perl modules.

Note: A # inside a quoted string is just a character, not a comment.

Example: Comments and POD

perl
use strict;
use warnings;

# This is a single-line comment
print "Step one\n";    # comment after code

=begin comment

This whole block is ignored by Perl,
so it works like a multi-line comment.

=end comment

=cut

print "Step two # not a comment\n";

# Output:
# Step one
# Step two # not a comment
Common Mistakes
  1. Expecting C-style /* */ block comments to work
  2. Forgetting the =cut line that ends a POD block
  3. Starting POD directives such as =pod anywhere but at the beginning of a line
Chapter Summary
  • # starts a comment
  • POD blocks can hide multiple lines
  • A POD block ends with =cut
  • A # inside a string is not a comment
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.