Updated April 5, 2023
Introduction to Perl multiline comment
Comments are the friends of developers in any programming language that makes the program user friendly, but .the interpreter skips the part of the code containing comments. Comments do not have any impact on the functionality of the program. There are two types of comments in Perl, namely single line comment and multi-line comment where a multiline comment begins with (=begin) statement and ends with (=cut) statement, and the interpreter interprets (=begin) as the beginning of the multiline comment section and (=cut) as the end of the multiline comment section and everything between (=begin). The compiler ignores the (=cut) section.
Syntax to declare multiline comment in Perl:
=begin
Comments
=cut
Examples
Given below are the examples of Perl multiline comment:
Example #1
Perl program to demonstrate multiline comment by specifying the beginning and end of the multiline comment section using (=begin) and (=cut) statements.
Code:
=begin
making use of glob function by passing the path of the directory where the files are present to print the names of the files present in the directory
=cut
@filenames = glob('C:/Users/admin/Desktop/*');
print "The files present in the specified directory are:\n";
foreach $eachfile(@filenames){
print "$eachfile\n";
}
Output:
In the above program, we describe the program’s functionality in a multiline comment section using (=begin) and (=cut) statements followed by the program. Then we are making use of the glob() function by passing the path of the directory where the files are present to print the names of the files present in the directory. Then the file names present in the directory are printed as the output on the screen. The output is shown in the snapshot above.
Example #2
Perl program to demonstrate multiline comment by specifying the beginning and end of the multiline comment section using (=begin) and (=cut) statements.
Code:
=begin
making use of glob function by passing the path of the directory where the files are present to print the names of the files present in the directory
=cut
@filenames = glob('C:/Users/admin/Desktop/EDUCBA/*');
print "The files present in the specified directory are:\n";
foreach $eachfile(@filenames){
print "$eachfile\n";
}
Output:
In the above program, we describe the program’s functionality in a multiline comment section using (=begin) and (=cut) statements followed by the program. Then we are making use of the glob() function by passing the path of the directory where the files are present to print the names of the files present in the directory. Then the file names present in the directory are printed as the output on the screen. The output is shown in the snapshot above.
Example #3
Perl program to demonstrate multiline comment by specifying the beginning and end of the multiline comment section using (=begin) and (=cut) statements.
Code:
=begin
making use of glob function by passing the path of the directory where the files are present to print the names of the files present in the directory
=cut
@filenames = glob('E:/Images/*');
print "The files present in the specified directory are:\n";
foreach $eachfile(@filenames){
print "$eachfile\n";
}
Output:
In the above program, we describe the program’s functionality in a multiline comment section using (=begin) and (=cut) statements followed by the program. Then we are making use of the glob() function by passing the path of the directory where the files are present to print the names of the files present in the directory. Then the file names present in the directory are printed as the output on the screen. The output is shown in the snapshot above.
Example #4
Perl program to demonstrate multiline comment by specifying the beginning and end of the multiline comment section using (=begin) and (=cut) statements.
Code:
=begin
making use of glob function by passing the path of the directory where the files are present to print the names of the files present in the directory
=cut
@filenames = glob('F:/Music/*');
print "The files present in the specified directory are:\n";
foreach $eachfile(@filenames){
print "$eachfile\n";
}
Output:
In the above program, we describe the program’s functionality in a multiline comment section using (=begin) and (=cut) statements followed by the program. Then we are making use of the glob() function by passing the path of the directory where the files are present to print the names of the files present in the directory. Then the file names present in the directory are printed as the output on the screen. The output is shown in the snapshot above.
Example #5
Perl program to demonstrate multiline comment by specifying the beginning and end of the multiline comment section using (=begin) and (=cut) statements.
Code:
=begin
making use of glob function by passing the path of the directory where the files are present to print the names of the files present in the directory
=cut
@filenames = glob('D:/WindowsUpdate/*');
print "The files present in the specified directory are:\n";
foreach $eachfile(@filenames){
print "$eachfile\n";
}
Output:
In the above program, we describe the program’s functionality in a multiline comment section using (=begin) and (=cut) statements followed by the program. Then we are making use of the glob() function by passing the path of the directory where the files are present to print the names of the files present in the directory. Then the file names present in the directory are printed as the output on the screen. The output is shown in the snapshot above.
Recommended Articles
This is a guide to Perl multiline comment. Here we discuss the introduction and examples of Perl multiline comment, respectively. You may also have a look at the following articles to learn more –