Comments in Perl
Comments in any programming language are friends of developers. Comments can be used to make program user friendly and they are simply skipped by the interpreter without impacting code functionality.Single line comment
For example, in the above program a line starting with hash # is a comment.
Simply saying comments in Perl start with a hash symbol and run to the end of the line:
# This is a comment in Perl
Multi line comment symbol
Lines starting with = are interpreted as the start of a section of embedded documentation (pod), and all subsequent lines until the next =cut are ignored by the compiler. Following is the example:
#! /usr/bin/perl
# This is a single line comment
print "Hello, world\n";
=begin comment
This is all part of multi line comment.
You can use as many lines as you like
These comments will be ignored by the
Compiler until the next =cut is encountered.
=cutThis will produce following result:
Hello, world
White spaces in Perl
A Perl program does not care about white spaces. Following program works perfectly fine:#! /usr/bin/perl
print "Hello, world\n";But if spaces are inside the quoted strings then they would be printed as is. For example:
#!/usr/bin/perl
# This would print with a line break in the middle
print "Hello world\n";
This will produce following result:
Hello world
All types of white space like spaces, tabs, new lines, etc. are equivalent
for the interpreter when they are used outside of the quotes. A line containing
only white space, possibly with a comment, is known as a blank line, and Perl
totally ignores it.
No comments:
Post a Comment