1 00:00:00 --> 00:00:04 Welcome to the spoken tutorial on Comments in Perl. 2 00:00:05 --> 00:00:07 In this tutorial, we will learn about 3 00:00:08 --> 00:00:09 Comments in Perl 4 00:00:10 --> 00:00:17 I am using Ubuntu Linux12.04 operating system and Perl 5.14.2 5 00:00:18 --> 00:00:22 that is, Perl revision 5 version 14 and subversion 2 6 00:00:23 --> 00:00:26 I will also be using the gedit Text Editor. 7 00:00:27 --> 00:00:30 You can use any text editor of your choice. 8 00:00:31 --> 00:00:36 You should have Basic knowledge of Compiling, Executing and Variables in Perl 9 00:00:37 --> 00:00:42 If not, please go through the relevant spoken tutorials on the spoken tutorial website 10 00:00:43 --> 00:00:46 Commenting a piece of code in Perl can be done in two ways: 11 00:00:47 --> 00:00:47 Single Line 12 00:00:48 --> 00:00:48 Multi Line 13 00:00:49 --> 00:00:54 This type of comment is used when user wants to comment a single line of code or 14 00:00:55 --> 00:01:00 to add one liner text to explain the functionality of a piece of code 15 00:01:01 --> 00:01:04 This type of comment starts with the symbol # (hash) . 16 00:01:05 --> 00:01:10 Here is a demo. Let us open a new file in the Text Editor. 17 00:01:11 --> 00:01:18 Open the Terminal and type - gedit comments dot pl space & 18 00:01:19 --> 00:01:26 Once again, reminding you that the ampersand is used to free the command prompt in the terminal and press enter. 19 00:01:27 --> 00:01:28 Now type the following commands. 20 00:01:29 --> 00:01:36 hash Declaring count variable 'press Enter 21 00:01:37 --> 00:01:44 dollar count space equal to space 1 semicolon press enter 22 00:01:45 --> 00:02:02 print space double quotes Count is dollar count slash n close double quote semicolon space hash prints Count is 1 23 00:02:03 --> 00:02:07 Now Save this file by pressing ctlr S and execute the Perl script. 24 00:02:08 --> 00:02:17 Switch to the Terminal, and type perl hyphen c comments dot pl and press Enter. 25 00:02:18 --> 00:02:20 This tells us that there is no syntax error 26 00:02:21 --> 00:02:27 Now type perl comments dot pl and press Enter. 27 00:02:28 --> 00:02:32 It will show the following output - Count is 1 28 00:02:33 --> 00:02:35 Let us switch back to gedit. 29 00:02:36 --> 00:02:39 In gedit, go to the first line and press enter. 30 00:02:40 --> 00:02:43 Go back to the first line and type the following command. 31 00:02:44 --> 00:02:51 Hash exclamation mark slash usr slash bin slash perl 32 00:02:52 --> 00:02:58 This line in Perl is called as a shebang line and is the first line in a Perl program. 33 00:02:59 --> 00:03:02 It tells where to find the Perl Interpreter. 34 00:03:03 --> 00:03:10 Note: Though this line starts with hash symbol, it will not be considered as a single line comment by Perl. 35 00:03:11 --> 00:03:12 Now let us look at multiline comments 36 00:03:13 --> 00:03:16 Multi Line This type of comment is used 37 00:03:17 --> 00:03:24 when user wants to comment a piece of code or to add description/usage of piece of code 38 00:03:25 --> 00:03:32 This type of comment starts with the symbol equal to head and ends with equal to cut 39 00:03:33 --> 00:03:38 Lets switch back to gedit and type the following in the comments dot pl file 40 00:03:39 --> 00:03:44 at the end of file type equal to head, press Enter 41 00:03:45 --> 00:03:58 print space double quote count variable is used for counting purpose close double quote press enter. 42 00:03:59 --> 00:04:00 equal to cut 43 00:04:01 --> 00:04:04 Save the file, close it and execute the Perl script. 44 00:04:05 --> 00:04:12 On the Terminal, type perl hyphen c comments dot pl and press Enter. 45 00:04:13 --> 00:04:14 No syntax error 46 00:04:15 --> 00:04:20 so let us execute it perl comments dot pl 47 00:04:21 --> 00:04:26 It will show the same output as before. Count is 1 48 00:04:27 --> 00:04:31 It does not print the sentence “count variable is used for counting purpose” 49 00:04:32 --> 00:04:39 This is because we commented the portion using equal to head and equal to cut 50 00:04:40 --> 00:04:47 You can either use =head =cut or =begin =end. 51 00:04:48 --> 00:04:51 These are not the special keywords used by Perl. 52 00:04:52 --> 00:05:01 Please note there should not be any leading or trailing space(s) before = to sign and after the head, cut, begin or end word. 53 00:05:02 --> 00:05:04 Open the Terminal once again. 54 00:05:05 --> 00:05:14 And Type - gedit commentsExample dot pl space & and press Enter. 55 00:05:15 --> 00:05:18 Type the following commands as shown on the screen. 56 00:05:19 --> 00:05:27 Here I am declaring two variables firstNum and secondNum and I am assigning some values to them. 57 00:05:28 --> 00:05:31 Then I have commented this portion here. 58 00:05:32 --> 00:05:38 Now I added these two numbers and assign the value to a third variable named addition. 59 00:05:39 --> 00:05:43 Next I want to print the value using print command. 60 00:05:44 --> 00:05:48 Save the file and execute the Perl script on the Terminal. 61 00:05:49 --> 00:05:56 On terminal type perl hyphen c commentsExample dot pl, press Enter. 62 00:05:57 --> 00:05:58 There is no syntax error 63 00:05:59 --> 00:06:00 So execute the script by typing 64 00:06:01 --> 00:06:06 perl commentsExample dot pl press enter 65 00:06:07 --> 00:06:11 It will show the following output. Addition is 30 66 00:06:12 --> 00:06:15 This brings us to the end of this tutorial. 67 00:06:16 --> 00:06:18 Here we learnt, To Add Comments in Perl 68 00:06:19 --> 00:06:22 Write a perl script to find square of a number. 69 00:06:23 --> 00:06:29 Explain the functionality of the code written using: Single Line Comment & Mutli Line Comment. 70 00:06:30 --> 00:06:33 Watch the video available at the following link 71 00:06:34 --> 00:06:36 It summarises the Spoken Tutorial project 72 00:06:37 --> 00:06:41 If you do not have good bandwidth, you can download and watch it 73 00:06:42 --> 00:06:43 The Spoken Tutorial Project Team 74 00:06:44 --> 00:06:47 Conducts workshops using spoken tutorials 75 00:06:48 --> 00:06:50 Gives certificates to those who pass an online test 76 00:06:51 --> 00:06:57 For more details, please write to contact at spoken hyphen tutorial dot org 77 00:06:58 --> 00:07:02 Spoken Tutorial Project is a part of the Talk to a Teacher project 78 00:07:03 --> 00:07:10 It is supported by the National Mission on Education through ICT, MHRD, Government of India 79 00:07:11 --> 00:07:14 More information on this Mission is available at the following link. 80 00:07:15 --> 00:07:20 Hope you enjoyed this Perl tutorial. This is Amol Brahmankar signing off. Thanks for joining.