Difference between revisions of "PERL/C2/Comments-in-Perl/English"
(Created page with ''''Title of script''': Comments in Perl '''Author: Amol''' '''Keywords: Comments in Perl, Video Tutorials, Scalars in Perl''' {| style="border-spacing:0;" | style="border:0.…') |
Nancyvarkey (Talk | contribs) |
||
(2 intermediate revisions by one other user not shown) | |||
Line 17: | Line 17: | ||
|- | |- | ||
| style="border:0.5pt solid #000000;padding:0.106cm;"| Slide:Learning Objectives | | style="border:0.5pt solid #000000;padding:0.106cm;"| Slide:Learning Objectives | ||
− | | style="border:0.5pt solid #000000;padding:0.106cm;"| In this tutorial, we will learn about | + | | style="border:0.5pt solid #000000;padding:0.106cm;"| In this tutorial, we will learn about comments in '''Perl'''. |
− | + | ||
− | + | ||
|- | |- | ||
Line 34: | Line 32: | ||
You can use any text editor of your choice. | You can use any text editor of your choice. | ||
+ | |- | ||
+ | | style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding:0.106cm;"| Slide:System Requirements | ||
+ | | style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding:0.106cm;"| You should have basic knowledge of compiling, executing and '''Variables''' in '''Perl'''. | ||
− | + | If not, please go through the relevant spoken tutorials on the spoken tutorial website. | |
− | + | ||
− | If not, please go through the relevant spoken tutorials on the spoken tutorial website | + | |
|- | |- | ||
Line 62: | Line 61: | ||
| style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding:0.106cm;"| Here is a demo. | | style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding:0.106cm;"| Here is a demo. | ||
− | Let us open a new file in the Text Editor. | + | Let us open a new file in the '''Text Editor'''. |
|- | |- | ||
Line 73: | Line 72: | ||
'''gedit comments dot pl &''' | '''gedit comments dot pl &''' | ||
− | |||
− | |||
− | |||
|- | |- | ||
Line 93: | Line 89: | ||
'''hash Declaring count variable''' | '''hash Declaring count variable''' | ||
− | ''' | + | press '''enter''' |
'''dollar count space equal to space 1 semicolon''' | '''dollar count space equal to space 1 semicolon''' | ||
− | ''' | + | press '''enter''' |
'''print space double quotes Count is dollar count slash n double quote complete semicolon space hash prints Count is 1''' | '''print space double quotes Count is dollar count slash n double quote complete semicolon space hash prints Count is 1''' | ||
Line 103: | Line 99: | ||
|- | |- | ||
| style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding:0.106cm;"| Save the file. | | style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding:0.106cm;"| Save the file. | ||
− | | style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding:0.106cm;"| Now | + | | style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding:0.106cm;"| Now save this file by pressing '''Ctlr S''' and execute the '''Perl''' script. |
|- | |- | ||
Line 118: | Line 114: | ||
This tells us that there is no syntax error | This tells us that there is no syntax error | ||
− | |||
− | |||
− | |||
|- | |- | ||
Line 149: | Line 142: | ||
| style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding:0.106cm;"| Let us switch back to '''gedit'''. | | style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding:0.106cm;"| Let us switch back to '''gedit'''. | ||
− | in '''gedit''', go to the first line and press enter. | + | in '''gedit''', go to the first line and press '''enter'''. |
− | Go back to the first line and type the following | + | Go back to the first line and type the following command. |
'''Hash exclamation mark slash usr slash bin slash perl''' | '''Hash exclamation mark slash usr slash bin slash perl''' | ||
− | |||
− | |||
− | |||
|- | |- | ||
Line 166: | Line 156: | ||
|- | |- | ||
| style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding:0.106cm;"| Slide | | style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding:0.106cm;"| Slide | ||
− | | style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding:0.106cm;"| '''Note:''' Though this line starts with hash''' '''symbol, it will not be considered as a single line comment by '''Perl'''. | + | | style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding:0.106cm;"| '''Note:''' Though this line starts with hash''' '''symbol, it will not be considered as a '''single line comment''' by '''Perl'''. |
− | Now let us look at multiline comments | + | Now let us look at '''multiline comments'''. |
|- | |- | ||
Line 174: | Line 164: | ||
| style="border:0.5pt solid #000000;padding:0.106cm;"| '''Multi Line''' | | style="border:0.5pt solid #000000;padding:0.106cm;"| '''Multi Line''' | ||
− | This type of comment is used | + | This type of '''comment''' is used |
* when user wants to comment a piece of code or | * when user wants to comment a piece of code or | ||
* to add description/usage of piece of code | * to add description/usage of piece of code | ||
− | This type of comment starts with the symbol '''equal to | + | This type of '''comment''' starts with the symbol '''equal to ''head''''' and ends with '''equal to ''cut''''' |
|- | |- | ||
Line 195: | Line 185: | ||
| style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding:0.106cm;"| Lets switch back to '''gedit''' and type the following - | | style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding:0.106cm;"| Lets switch back to '''gedit''' and type the following - | ||
− | in the '''comments dot pl '''file | + | in the '''comments dot pl '''file, at the end of file, type |
− | + | ||
− | at the end of file type | + | |
'''equal to head''' | '''equal to head''' | ||
− | ''' | + | press '''enter''' |
'''print space double quote count variable will be used for counting purpose double quote complete''' | '''print space double quote count variable will be used for counting purpose double quote complete''' | ||
− | ''' | + | press '''enter''' |
'''equal to cut''' | '''equal to cut''' | ||
Line 233: | Line 221: | ||
and press '''Enter''' | and press '''Enter''' | ||
− | | style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding:0.106cm;"| | + | | style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding:0.106cm;"| So let us execute it |
'''perl comments dot pl''' | '''perl comments dot pl''' | ||
− | |||
− | |||
|- | |- | ||
Line 251: | Line 237: | ||
'''“count variable will be used for counting purpose”''' | '''“count variable will be used for counting purpose”''' | ||
− | | style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding:0.106cm;"| It does not print the sentence '''“count variable | + | | style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding:0.106cm;"| It does not print the sentence '''“count variable is be used for counting purpose”''' |
|- | |- | ||
Line 265: | Line 251: | ||
|- | |- | ||
| style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding:0.106cm;"| | | style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding:0.106cm;"| | ||
− | | style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding:0.106cm;"| '''Please note''' there should not be any leading or trailing space(s) before '''<nowiki>= to</nowiki>''' sign and after the '''head | + | | style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding:0.106cm;"| '''Please note''' there should not be any leading or trailing space(s) before '''<nowiki>= to</nowiki>''' sign and after the '''head, cut, begin''' or '''end''' word. |
|- | |- | ||
Line 274: | Line 260: | ||
| style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding:0.106cm;"| Type | | style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding:0.106cm;"| Type | ||
− | '''gedit comments.pl &''' | + | ''' perl gedit comments.pl &''' |
and press '''Enter'''. | and press '''Enter'''. | ||
Line 309: | Line 295: | ||
'''print “Addition is $addition”;''' | '''print “Addition is $addition”;''' | ||
| style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding:0.106cm;"| Type the following commands as shown on the screen. | | style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding:0.106cm;"| Type the following commands as shown on the screen. | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
Here I am declaring two variables '''firstNum '''and '''secondNum '''and I am assigning some values to them. | Here I am declaring two variables '''firstNum '''and '''secondNum '''and I am assigning some values to them. | ||
+ | |||
+ | |||
Then I have commented this portion here. | Then I have commented this portion here. | ||
− | |||
− | |||
+ | |||
+ | |||
+ | Now I added these two numbers and assigned the value to a third '''variable''' named '''addition'''. | ||
+ | |||
+ | |||
+ | |||
+ | Next I want to print the value using '''print command'''. | ||
|- | |- | ||
Line 332: | Line 330: | ||
− | On terminal type | + | On '''terminal''' type |
'''perl hyphen c commentsExample dot pl''' | '''perl hyphen c commentsExample dot pl''' | ||
− | press enter | + | press '''enter''' |
− | There is no syntax error | + | There is no syntax error. |
− | + | So execute the script by typing | |
'''perl commentsExample dot pl''' | '''perl commentsExample dot pl''' | ||
− | press enter | + | press '''enter''' |
|- | |- | ||
Line 370: | Line 368: | ||
* Single Line Comment. | * Single Line Comment. | ||
* Mutli Line Comment. | * Mutli Line Comment. | ||
− | |||
− | |||
|- | |- | ||
Line 379: | Line 375: | ||
It summarises the Spoken Tutorial project | It summarises the Spoken Tutorial project | ||
− | If you do not have good bandwidth, you can | + | If you do not have good bandwidth, you can download and watch it |
− | + | ||
− | download and watch it | + | |
|- | |- | ||
Line 387: | Line 381: | ||
| style="border:0.5pt solid #000000;padding:0.106cm;"| The Spoken Tutorial Project Team | | style="border:0.5pt solid #000000;padding:0.106cm;"| The Spoken Tutorial Project Team | ||
− | Conducts workshops using spoken tutorials | + | *Conducts workshops using spoken tutorials |
− | Gives certificates to those who pass an online | + | *Gives certificates to those who pass an online test |
− | + | For more details, please write to contact at spoken hyphen tutorial dot org | |
− | + | ||
− | For more details, please write to | + | |
− | + | ||
− | contact at spoken hyphen tutorial dot org | + | |
|- | |- | ||
| style="border:0.5pt solid #000000;padding:0.106cm;"| Acknowledgment | | style="border:0.5pt solid #000000;padding:0.106cm;"| Acknowledgment | ||
− | | style="border:0.5pt solid #000000;padding:0.106cm;"| Spoken Tutorial Project is a part of the Talk to a | + | | style="border:0.5pt solid #000000;padding:0.106cm;"| Spoken Tutorial Project is a part of the Talk to a Teacher project. |
− | + | ||
− | Teacher project | + | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | It is supported by the National Mission on Education through ICT, MHRD, Government of India. | |
− | at the following link. | + | More information on this Mission is available at the following link. |
|- | |- |
Latest revision as of 09:43, 27 June 2018
Title of script: Comments in Perl
Author: Amol
Keywords: Comments in Perl, Video Tutorials, Scalars in Perl
|
|
Slide | Welcome to the spoken tutorial on Comments in Perl. |
Slide:Learning Objectives | In this tutorial, we will learn about comments in Perl. |
Slide:System Requirements | I am using Ubuntu Linux12.04 operating system and
Perl 5.14.2 that is, Perl revision 5 version 14 and subversion 2
You can use any text editor of your choice. |
Slide:System Requirements | You should have basic knowledge of compiling, executing and Variables in Perl.
If not, please go through the relevant spoken tutorials on the spoken tutorial website. |
Slide | Commenting a piece of code in Perl can be done in two ways:
a. Single Line b. Multi Line |
Slide | Single Line
This type of comment is used
This type of comment starts with the symbol # (hash). |
Here is a demo.
Let us open a new file in the Text Editor. | |
Switch to the Terminal and type
gedit singlemulti.pl & and press Enter. |
Open the Terminal and type -
gedit comments dot pl & |
Highlight & | Once again, reminding you that the ampersand is used to free the command prompt in the terminal. And press enter |
Type
# Declaring count variable $count = 1; print “Count is $count \n”; # prints Count is 1 |
Now type the following commands.
hash Declaring count variable press enter dollar count space equal to space 1 semicolon press enter print space double quotes Count is dollar count slash n double quote complete semicolon space hash prints Count is 1 |
Save the file. | Now save this file by pressing Ctlr S and execute the Perl script. |
Switch to the Terminal and type
perl -c singlemulti.pl and press Enter |
Switch to the Terminal, and type
perl hyphen c comments dot pl and press Enter. This tells us that there is no syntax error |
Then type
perl singlemulti.pl and press Enter |
Now type
perl comments dot pl and press Enter. |
Point to the output | It will show the following output -
Count is 1 |
Go to gedit and type
#!/usr/bin/perl
|
Let us switch back to gedit.
in gedit, go to the first line and press enter. Go back to the first line and type the following command. Hash exclamation mark slash usr slash bin slash perl |
Slide | This line in Perl is called as a shebang line and is the first line in a Perl program.
It tells where to find the Perl Interpreter. |
Slide | Note: Though this line starts with hash symbol, it will not be considered as a single line comment by Perl.
Now let us look at multiline comments. |
Slide | Multi Line
This type of comment is used
This type of comment starts with the symbol equal to head and ends with equal to cut |
Type
=head print “ count variable will be used for counting purpose” =cut above $count = 1; |
Lets switch back to gedit and type the following -
in the comments dot pl file, at the end of file, type equal to head press enter print space double quote count variable will be used for counting purpose double quote complete press enter equal to cut |
Save the file and close it. | Save the file, close it and execute the Perl script. |
Switch to the Terminal and type
perl -c singlemulti.pl and press Enter. |
On the Terminal, type
perl hyphen c comments dot pl and press Enter. No syntax error |
Then type
perl singlemulti.pl and press Enter |
So let us execute it
perl comments dot pl |
Point to the output | It will show the same output as before.
Count is 1 |
Switch back to gedit
Point to the sentence “count variable will be used for counting purpose” |
It does not print the sentence “count variable is be used for counting purpose” |
Point to =head and =cut | This is because we commented the portion using equal to head and equal to cut |
Slide | You can either use =head =cut or =begin =end.
These are not the special keywords used by Perl. |
Please note there should not be any leading or trailing space(s) before = to sign and after the head, cut, begin or end word. | |
Switch to the Terminal | Open the Terminal once again. |
Type
perl gedit comments.pl & and press Enter. |
And Type -
gedit commentsExample dot pl & and press Enter. |
Type
# Here I am going to explain commenting in Perl # Following is the scalar variable declaration $firstNum = 10; $secondNum = 20;
following piece of code adds 2 numbers puts the result into a 3rd variable and prints this 3rd variable =cut $addition = $firstNum + $secondNum; print “Addition is $addition”; |
Type the following commands as shown on the screen.
Then I have commented this portion here.
Now I added these two numbers and assigned the value to a third variable named addition.
Next I want to print the value using print command. |
Save the file and switch to the Terminal.
Type perl -c comments.pl perl comments.pl |
Save the file and execute the Perl script on the Terminal.
perl hyphen c commentsExample dot pl press enter There is no syntax error. So execute the script by typing
press enter |
Point to the output | It will show the following output.
Addition is 30 |
Summary | This brings us to the end of this tutorial.
Here we learnt, To Add Comments in Perl |
Assignment | Assignment
|
About the Project | Watch the video available at the following link
It summarises the Spoken Tutorial project If you do not have good bandwidth, you can download and watch it |
Spoken Tutorial Workshops | The Spoken Tutorial Project Team
For more details, please write to contact at spoken hyphen tutorial dot org |
Acknowledgment | Spoken Tutorial Project is a part of the Talk to a Teacher project.
It is supported by the National Mission on Education through ICT, MHRD, Government of India. More information on this Mission is available at the following link. |
Hope you enjoyed this Perl tutorial.
This is Amol Brahmankar signing off. Thanks for joining. |