Difference between revisions of "PERL/C3/Including-files-or-modules/English-timed"

From Script | Spoken-Tutorial
Jump to: navigation, search
 
(6 intermediate revisions by one other user not shown)
Line 5: Line 5:
 
|-
 
|-
 
|00:01
 
|00:01
|Welcome to the''' Spoken Tutorial''' on''' Including files or modules in a PERL program'''
+
|Welcome to the''' Spoken Tutorial''' on''' Including files or modules''' in a '''PERL''' program.
  
 
|-
 
|-
 
|00:08
 
|00:08
|In this tutorial we will learn to use
+
|In this tutorial, we will learn to use:
* '''do'''
+
'''do'''
* '''use '''and
+
'''use '''and
* '''require'''
+
'''require'''
methods in''' PERL''' programming.
+
'''method'''s in PERL programming.
  
 
|-
 
|-
 
|00:16
 
|00:16
|For this tutorial, I am using
+
|For this tutorial, I am using:
* '''Ubuntu Linux 12.04''' operating system
+
'''Ubuntu Linux 12.04''' operating system
* '''Perl 5.14.2 and'''
+
'''Perl 5.14.2''' and
* '''gedit''' Text Editor
+
'''gedit''' Text Editor.
  
 
|-
 
|-
 
|00:28
 
|00:28
|You can use any text editor of your choice.
+
|You can use any '''text editor''' of your choice.
  
 
|-
 
|-
Line 36: Line 36:
 
|-
 
|-
 
|00:44
 
|00:44
|'''Do Method''': These are simple ways to include the source code from other files into the current script file.
+
|''''do()' method''': These are simple ways to include the source code from other files into the current script file.
  
 
|-
 
|-
 
|00:53
 
|00:53
|Let us understand how to use '''do()''' method.
+
|Let us understand how to use '''do() method'''.
  
 
|-
 
|-
 
|00:57
 
|00:57
|Open a new file in your text editor and name it as '''datetime dot pl'''  
+
|Open a new file in your text editor and name it as '''datetime dot pl'''.
  
 
|-
 
|-
Line 52: Line 52:
 
|-
 
|-
 
|01:09
 
|01:09
|From here onwards, remember to press the '''Enter key '''after every command on the '''terminal'''.
+
|From here onwards, remember to press the '''Enter''' key after every command on the '''terminal'''.
  
 
|-
 
|-
Line 60: Line 60:
 
|-
 
|-
 
|01:18
 
|01:18
|The current date and time is stored in a variable''' dollar datestring.'''
+
|The current date and time are stored in a variable''' dollar datestring.'''
  
 
|-
 
|-
 
|01:23
 
|01:23
|Here, I have a''' function''' by name''' msgThanks,''' which returns a “'''Thank you'''” message.
+
|Here, I have a function by name "msgThanks" which returns a “Thank you” message.
  
 
|-
 
|-
 
|01:31
 
|01:31
|Now, press''' Ctrl+S''' to save the file.
+
|Now, press''' Ctrl+S''' to '''save''' the file.
  
 
|-
 
|-
 
|01:35
 
|01:35
|Next let us look at another '''Perl '''program which will make use of this file''' datetime dot pl'''
+
|Next, let us look at another '''Perl '''program which will make use of this file''' datetime dot pl'''.
  
 
|-
 
|-
 
|01:43
 
|01:43
|Open a new file in your text editor and name it as '''main dot pl'''  
+
|Open a new file in your '''text editor''' and name it as '''main dot pl'''.
  
 
|-
 
|-
Line 92: Line 92:
 
|-
 
|-
 
|02:03
 
|02:03
|'''do()''' method is called with the filename from where we want to use the code.
+
|'do()' method is called with the filename from where we want to use the code.
  
 
|-
 
|-
 
|02:09
 
|02:09
|Current date and time is stored in the''' $datestring''' variable of''' datetime dot pl file.'''
+
|Current date and time are stored in the''' $datestring''' variable of''' datetime dot pl file.'''
  
 
|-
 
|-
Line 104: Line 104:
 
|-
 
|-
 
|02:21
 
|02:21
|Now, press''' Ctrl+S''' to save the file.
+
|Now, press''' Ctrl+S''' to '''save''' the file.
  
 
|-
 
|-
 
|02:25
 
|02:25
|Let us execute the program.
+
|Let us '''execute''' the program.
  
 
|-
 
|-
 
|02:27
 
|02:27
|Switch back to the''' terminal''' and type '''perl main dot pl '''and press''' Enter'''
+
|Switch back to the''' terminal''' and type: '''perl main dot pl '''and press''' Enter'''.
  
 
|-
 
|-
 
|02:34
 
|02:34
|Observe the output on the '''terminal.'''
+
|Observe the output on the terminal.
  
 
|-
 
|-
 
|02:37
 
|02:37
|Next we will learn how to use''' require method''' and''' use method''' in a '''Perl''' program.
+
|Next, we will learn how to use''' require()''' method and''' use()''' method in a '''Perl''' program.
  
 
|-
 
|-
Line 128: Line 128:
 
|-
 
|-
 
|02:52
 
|02:52
| '''use''' method is used only for the '''modules'''.
+
| '''use() method''' is used only for the '''modules'''.
  
 
|-
 
|-
 
|02:56
 
|02:56
| It is verified at the time of '''compilation'''
+
| It is verified at the time of '''compilation'''.
  
 
|-
 
|-
 
|02:59
 
|02:59
|There is no need to give the '''file extension'''
+
|There is no need to give the file '''extension'''.
  
 
|-
 
|-
 
| 03:03
 
| 03:03
|  '''require '''method is used for both '''Perl''' '''programs '''and '''modules'''
+
|  '''require()''' method is used for both Perl programs and '''modules'''.
  
 
|-
 
|-
 
|03:08
 
|03:08
| It is verified at the '''run time'''
+
| It is verified at the '''run''' time.
  
 
|-
 
|-
Line 152: Line 152:
 
|-
 
|-
 
|03:14
 
|03:14
| The syntax of '''use method '''is '''use module name semicolon'''
+
| The syntax of '''use''' method is: '''use module name semicolon'''.
  
 
|-
 
|-
 
|03:20
 
|03:20
| '''Perl modules''' are the files which end with '''.pm''' extension.
+
| '''Perl modules''' are the files which end with '.pm' extension.
  
 
|-
 
|-
 
|03:25
 
|03:25
| Reusability of code is implemented through '''modules'''.
+
| Re-usability of code is implemented through '''modules'''.
  
 
|-
 
|-
 
|03:30
 
|03:30
| These are similar to libraries in other languages.
+
| These are similar to '''libraries''' in other (computer) languages.
  
 
|-
 
|-
 
|03:35
 
|03:35
|Now I will show a simple program with the''' use method''' to include a''' module''' in '''Perl''' code.
+
|Now, I will show a simple program with the''' use method''' to include a module in Perl code.
  
 
|-
 
|-
 
|03:43
 
|03:43
|Open a new file In your '''text editor '''and name it as '''sum dot pm.'''  
+
|Open a new file in your '''text editor '''and name it as '''sum dot pm.'''  
  
 
|-
 
|-
Line 184: Line 184:
 
|-
 
|-
 
|04:01
 
|04:01
|Now, press''' Ctrl+S''' to save the file
+
|Now, press''' Ctrl+S''' to '''save''' the file.
  
 
|-
 
|-
 
|04:05
 
|04:05
|We will write another '''Perl''' script where we’ll use this''' sum dot pm''' file.
+
|We will write another '''Perl script''' where we’ll use this''' sum dot pm''' file.
  
 
|-
 
|-
 
| 04:11
 
| 04:11
| Let me open the sample program '''app dot pl''' file which I have saved already
+
| Let me open the sample program '''app dot pl''' file which I have saved already.
  
 
|-
 
|-
Line 204: Line 204:
 
|-
 
|-
 
|04:25
 
|04:25
|The first line shows the use method with the '''module '''name.
+
|The first line shows the '''use''' method with the module name.
  
 
|-
 
|-
 
|04:29
 
|04:29
|In our case, the '''module '''name is '''sum'''.
+
|In our case, the module name is 'sum'.
  
 
|-
 
|-
 
|04:33
 
|04:33
|We are passing 1,7,5,4,9 as '''input parameters '''to the function '''total''' in '''sum dot pm '''file.
+
|We are passing 1, 7, 5, 4, 9 as '''input parameters '''to the function '''total()''' in '''sum dot pm '''file.
  
 
|-
 
|-
 
|04:44
 
|04:44
|Again, in the next line, we are passing 1 to 10 as '''input parameters '''to the same '''function'''.
+
|Again, in the next line, we are passing 1 to 10 as '''input parameters '''to the same function.
  
 
|-
 
|-
 
|04:52
 
|04:52
|Now, press''' Ctrl+S''' to save the file.
+
|Now, press''' Ctrl+S''' to '''save''' the file.
  
 
|-
 
|-
 
|04:56
 
|04:56
|Let us execute the program.
+
|Let us '''execute''' the program.
  
 
|-
 
|-
 
|04:59
 
|04:59
|Switch back to the''' terminal''' and type '''perl app dot pl''' and Press '''Enter'''
+
|Switch back to the terminal and type: '''perl app dot pl''' and press '''Enter'''.
  
 
|-
 
|-
 
|05:06
 
|05:06
|Observe the output displayed on the '''terminal.'''
+
|Observe the output displayed on the terminal.
  
 
|-
 
|-
Line 240: Line 240:
 
|-
 
|-
 
|05:18
 
|05:18
|At the beginning of the source code, add the lines  '''use strict semicolon''' '''use warnings semicolon'''
+
|At the beginning of the source code, add the lines  "use strict" semicolon, "use warnings" semicolon.
  
 
|-
 
|-
 
|05:27
 
|05:27
|'''use strict''' and''' use warnings''' are '''compiler flags '''that instruct''' Perl''' to behave in a stricter way.
+
|"use strict" and "use warnings" are '''compiler flags '''that instruct Perl to behave in a stricter way.
  
 
|-
 
|-
Line 252: Line 252:
 
|-
 
|-
 
|05:39
 
|05:39
|'''use strict''' forces the user to declare all the '''variables''' used in the program.
+
|'''use strict''' forces the user to declare all the variables used in the program.
  
 
|-
 
|-
Line 264: Line 264:
 
|-
 
|-
 
|05:56
 
|05:56
|Assume that we forgot to declare the '''variable $sum '''as''' my'''.
+
|Assume that we forgot to declare the variable '''$sum '''as''' my'''.
  
 
|-
 
|-
Line 272: Line 272:
 
|-
 
|-
 
|06:06
 
|06:06
|Press''' Ctrl+S''' to save the file.
+
|Press''' Ctrl+S''' to '''save''' the file.
  
 
|-
 
|-
 
|06:09
 
|06:09
|Switch back to the''' terminal''' and type '''perl app dot pl'''
+
|Switch back to the terminal and type: '''perl app dot pl'''.
  
 
|-
 
|-
Line 284: Line 284:
 
|-
 
|-
 
|06:21
 
|06:21
|The first set of lines displayed on the '''terminal''' are '''error messages''' generated by “'''use strict'''”.
+
|The first set of lines displayed on the terminal are '''error messages''' generated by “use strict”.
  
 
|-
 
|-
 
|06:29
 
|06:29
|The last two are the abort messages.
+
|The last two are the '''abort''' messages.
  
 
|-
 
|-
Line 296: Line 296:
 
|-
 
|-
 
|06:36
 
|06:36
|Next let us see a '''Perl program '''where we use the''' require''' method.
+
|Next, let us see a Perl program where we use the''' require''' method.
  
 
|-
 
|-
Line 304: Line 304:
 
|-
 
|-
 
|06:48
 
|06:48
|Type the following code as displayed on the screen in your '''commonfunctions dot pl''' file.
+
|Type the following code as displayed on the screen in your '''commonfunctions dot pl''' file. Let us understand the code now.
Let us understand the code now.
+
  
 
|-
 
|-
 
|06:57
 
|06:57
|Here we can see a collection of commonly used '''functions'''.
+
|Here, we can see a collection of commonly used functions.
  
 
|-
 
|-
 
|07:01
 
|07:01
|The first '''function square()''' returns the square of a number.
+
|The first function, '''square()''', returns the square of a number.
  
 
|-
 
|-
 
|07:06
 
|07:06
|The second '''function square underscore root()''' returns the square root of a given number.
+
|The second function, '''square underscore root()''', returns the square root of a given number.
  
 
|-
 
|-
 
|07:12
 
|07:12
|Next '''function random underscore number()''' generates a random number.
+
|Next function, '''random underscore number()''', generates a random number.
  
 
|-
 
|-
 
|07:18
 
|07:18
|The last '''function random underscore range()''' generates a random number between a lower range and upper range of numbers.
+
|The last function '''random underscore range()''', generates a random number between a lower range and upper range of numbers.
  
 
|-
 
|-
 
|07:26
 
|07:26
|Note that we need the '''1 semicolon''' at the end of the file.
+
|Note that we need the '''1 semicolon''' (1;) at the end of the file.
  
 
|-
 
|-
 
|07:31
 
|07:31
|This is because''' Perl''' needs the last expression in the file to return a '''true value'''.
+
|This is because''' Perl''' needs the last expression in the file to return a '''true''' value.
  
 
|-
 
|-
 
|07:37
 
|07:37
|Now, press''' Ctrl+S''' to save the file.
+
|Now, press''' Ctrl+S''' to '''save''' the file.
  
 
|-
 
|-
 
|07:41
 
|07:41
|Next we will write a''' Perl''' program in which we’ll call these '''subroutines '''using''' require''' method.
+
|Next, we will write a Perl program in which we’ll '''call''' these '''subroutines '''using "require" method.
  
 
|-
 
|-
Line 353: Line 352:
 
|-
 
|-
 
|08:02
 
|08:02
|'''require''' reads the''' commonfunctions dot pl''' file containing '''Perl''' code and compiles it.
+
|'''require''' reads the''' commonfunctions dot pl''' file, containing Perl code, and compiles it.
  
 
|-
 
|-
Line 361: Line 360:
 
|-
 
|-
 
|08:17
 
|08:17
|One is to find the square of a number.
+
|1: (one) is to find the square of a number.
  
 
|-
 
|-
 
|08:20
 
|08:20
|Two is for square root of a number.
+
|2: Two is for square root of a number.
  
 
|-
 
|-
 
|08:23
 
|08:23
|Three is for a random number in the given range. Four is to quit the program.
+
|3: Three is for a random number in the given range. 4: Four is to quit the program.
  
 
|-
 
|-
 
|08:29
 
|08:29
|If option one is typed, it will ask the user to enter a number.
+
|If option 1 (one) is typed, it will ask the user to enter a number.
  
 
|-
 
|-
 
|08:34
 
|08:34
|The value is stored in''' $number.''' The value is to passed to the function''' square''' in''' commonfunctions dot pl''' file.
+
|The value is stored in''' $number.''' The value is passed to the function '''square()''' in''' commonfunctions dot pl''' file.
  
 
|-
 
|-
Line 385: Line 384:
 
|-
 
|-
 
|08:47
 
|08:47
|The '''print statement''' prints the square of a number as output.
+
|The '''print''' statement prints the square of a number as output.
  
 
|-
 
|-
 
|08:52
 
|08:52
|If option two is typed, the square root of a number is displayed as output.
+
|If option 2 (two) is typed, the square root of a number is displayed as output.
  
 
|-
 
|-
 
|08:58
 
|08:58
|The execution is followed as explained in the previous '''function square'''.
+
|The execution is followed as explained in the previous function '''square()'''.
  
 
|-
 
|-
 
|09:03
 
|09:03
|If option three is typed, a random number is displayed as output in the given range.
+
|If option 3 (three) is typed, a random number is displayed as output in the given range.
  
 
|-
 
|-
 
|09:09
 
|09:09
|Else if option is four, the program exits. If any option other than the ones specified is given, the '''print statement '''says “Incorrect option”.
+
|Else, if option is 4 (four), the program exits. If any option other than the ones specified is given, the '''print''' statement says “Incorrect option”.
  
 
|-
 
|-
 
|09:20
 
|09:20
|Note that in this program we have called only three functions out of four from '''commonfunctions dot pl'''.
+
|Note that in this program, we have called only three functions out of four from '''commonfunctions dot pl'''.
 
|-
 
|-
 
|09:28
 
|09:28
|Now, press''' Ctrl+S''' to save the file
+
|Now, press''' Ctrl+S''' to '''save''' the file.
  
 
|-
 
|-
 
|09:31
 
|09:31
|Let us execute the program.
+
|Let us '''execute''' the program.
  
 
|-
 
|-
 
|09:34
 
|09:34
|Switch back to the''' terminal''' and type '''perl callprogram dot pl'''
+
|Switch back to the terminal and type: '''perl callprogram dot pl'''.
  
 
|-
 
|-
 
|09:41
 
|09:41
|Observe the output
+
|Observe the output.
  
 
|-
 
|-
Line 428: Line 427:
 
|-
 
|-
 
|09:49
 
|09:49
|Type''' perl callprogram dot pl'''
+
|Type:''' perl callprogram dot pl'''.
  
 
|-
 
|-
 
|09:53
 
|09:53
|Now, '''Enter the Option''' as 3.
+
|Now, enter the option as 3.
  
 
|-
 
|-
Line 452: Line 451:
 
|-
 
|-
 
|10:11
 
|10:11
|This brings us to the end of this tutorial. Let us summarise.
+
|This brings us to the end of this tutorial. Let us summarize.
  
 
|-
 
|-
 
|10:16
 
|10:16
|In this tutorial we learnt to use
+
|In this tutorial, we learnt to use:
* '''do'''
+
'''do'''
* '''use'''
+
'''use'''
* '''require methods '''in''' PERL''' programming.
+
'''require methods '''in PERL programming.
  
 
|-
 
|-
 
|10:24
 
|10:24
|'''Note''': "'''use Module'''" is recommended over "'''require Module'''", because it determines '''module availability '''at '''compile time'''.
+
|Note: "use" '''module''' is recommended over "require" module, because it determines module availability at '''compile time'''.
 
|-
 
|-
 
|10:33
 
|10:33
|Here is an assignment for you. Write a''' Perl''' program''' reminder.pl''' where you will write a letter to the participants.
+
|Here is an assignment for you. Write a Perl program''' reminder.pl''' where you will write a letter to the participants.
  
 
|-
 
|-
 
|10:41
 
|10:41
|Prompt the user to enter''' To''' and''' From''' name
+
|Prompt the user to enter''' To''' and''' From''' name.
  
 
|-
 
|-
 
|10:45
 
|10:45
|Call the subroutines from''' Letter dot pm''' using '''‘use’''' method.
+
|'''Call''' the subroutines from''' Letter dot pm''' using ‘use’ method.
  
 
|-
 
|-
Line 482: Line 481:
 
|-
 
|-
 
|10:54
 
|10:54
| '''LetterDate()''' function returns the current date and time
+
| '''LetterDate()''' function returns the current date and time.
  
 
|-
 
|-
 
|10:58
 
|10:58
|'''To()''' function returns the name of the participants
+
|'''To()''' function returns the names of the participants.
  
 
|-
 
|-
 
|11:02
 
|11:02
| '''From()''' function returns the sender name
+
| '''From()''' function returns the sender's name.
  
 
|-
 
|-
 
|11:05
 
|11:05
|''' Lettermsg()''' function returns the content of the letter
+
|''' Lettermsg()''' function returns the contents of the letter.
  
 
|-
 
|-
 
|11:09
 
|11:09
|'''Thanksmsg()''' function returns thanks and regards.
+
|'''Thanksmsg()''' function returns "thanks" and "regards".
  
 
|-
 
|-
Line 506: Line 505:
 
|-
 
|-
 
| 11:20
 
| 11:20
|The video at the following link summarize the spoken tutotial project. Please download and watch it
+
|The video at the following link summarizes the spoken tutotial project. Please download and watch it.
  
 
|-
 
|-
 
|11:27
 
|11:27
|The''' Spoken Tutorial Project''' Team
+
|The''' Spoken Tutorial Project''' team:
 
+
conducts workshops using spoken tutorials and
* conducts workshops using spoken tutorials and
+
gives certificates on passing online tests.
* gives certificates on passing online tests.
+
  
 
|-
 
|-
Line 522: Line 520:
 
|11:40
 
|11:40
 
|Spoken Tutorial project is funded by NMEICT, MHRD, Government of India.
 
|Spoken Tutorial project is funded by NMEICT, MHRD, Government of India.
 
 
More information on this mission is available at this link.
 
More information on this mission is available at this link.
  
 
|-
 
|-
 
|11:51
 
|11:51
|This is Nirmala Venkat from IIT Bombay, signing off. Thanks for watching.
+
|This is Nirmala Venkat from '''IIT Bombay''', signing off. Thanks for watching.
  
 
|}
 
|}

Latest revision as of 18:23, 20 February 2017

Time Narration
00:01 Welcome to the Spoken Tutorial on Including files or modules in a PERL program.
00:08 In this tutorial, we will learn to use:

do use and require methods in PERL programming.

00:16 For this tutorial, I am using:

Ubuntu Linux 12.04 operating system Perl 5.14.2 and gedit Text Editor.

00:28 You can use any text editor of your choice.
00:32 To follow this tutorial, you should have working knowledge of Perl programming.
00:37 If not, then go through the relevant Perl spoken tutorials on the spoken tutorial website.
00:44 'do()' method: These are simple ways to include the source code from other files into the current script file.
00:53 Let us understand how to use do() method.
00:57 Open a new file in your text editor and name it as datetime dot pl.
01:03 In the datetime dot pl file, type the following code as displayed on the screen.
01:09 From here onwards, remember to press the Enter key after every command on the terminal.
01:15 Let us understand the code now.
01:18 The current date and time are stored in a variable dollar datestring.
01:23 Here, I have a function by name "msgThanks" which returns a “Thank you” message.
01:31 Now, press Ctrl+S to save the file.
01:35 Next, let us look at another Perl program which will make use of this file datetime dot pl.
01:43 Open a new file in your text editor and name it as main dot pl.
01:49 In the main dot pl file, type the following code as displayed on the screen.
01:55 Let me explain the code now.
01:58 Here, the first line prints the welcome message.
02:03 'do()' method is called with the filename from where we want to use the code.
02:09 Current date and time are stored in the $datestring variable of datetime dot pl file.
02:16 And at the end, we call the msgThanks() function from the same file.
02:21 Now, press Ctrl+S to save the file.
02:25 Let us execute the program.
02:27 Switch back to the terminal and type: perl main dot pl and press Enter.
02:34 Observe the output on the terminal.
02:37 Next, we will learn how to use require() method and use() method in a Perl program.
02:44 These methods are used - when we have collections of subroutines that can be used in multiple Perl programs.
02:52 use() method is used only for the modules.
02:56 It is verified at the time of compilation.
02:59 There is no need to give the file extension.
03:03 require() method is used for both Perl programs and modules.
03:08 It is verified at the run time.
03:10 One needs to give the file extension.
03:14 The syntax of use method is: use module name semicolon.
03:20 Perl modules are the files which end with '.pm' extension.
03:25 Re-usability of code is implemented through modules.
03:30 These are similar to libraries in other (computer) languages.
03:35 Now, I will show a simple program with the use method to include a module in Perl code.
03:43 Open a new file in your text editor and name it as sum dot pm.
03:49 In the sum dot pm file, type the following code as displayed on the screen.
03:55 Here, I have a simple function which will calculate the sum of a given set of numbers.
04:01 Now, press Ctrl+S to save the file.
04:05 We will write another Perl script where we’ll use this sum dot pm file.
04:11 Let me open the sample program app dot pl file which I have saved already.
04:17 In the app dot pl file, type the following code as displayed on the screen.
04:22 Let me explain the code now.
04:25 The first line shows the use method with the module name.
04:29 In our case, the module name is 'sum'.
04:33 We are passing 1, 7, 5, 4, 9 as input parameters to the function total() in sum dot pm file.
04:44 Again, in the next line, we are passing 1 to 10 as input parameters to the same function.
04:52 Now, press Ctrl+S to save the file.
04:56 Let us execute the program.
04:59 Switch back to the terminal and type: perl app dot pl and press Enter.
05:06 Observe the output displayed on the terminal.
05:10 Let us see few more options in use method. Switch back to sum dot pm in the text editor.
05:18 At the beginning of the source code, add the lines "use strict" semicolon, "use warnings" semicolon.
05:27 "use strict" and "use warnings" are compiler flags that instruct Perl to behave in a stricter way.
05:35 These are used to avoid common programming mistakes.
05:39 use strict forces the user to declare all the variables used in the program.
05:45 If there are errors, use strict will abort the execution.
05:50 use warnings will only provide warnings but continue with the execution.
05:56 Assume that we forgot to declare the variable $sum as my.
06:02 Let us now see how the same program is executed.
06:06 Press Ctrl+S to save the file.
06:09 Switch back to the terminal and type: perl app dot pl.
06:15 We can see that the program is aborted without executing the result.
06:21 The first set of lines displayed on the terminal are error messages generated by “use strict”.
06:29 The last two are the abort messages.
06:32 So, this is how the use method options work.
06:36 Next, let us see a Perl program where we use the require method.
06:41 Let me open the sample program commonfunctions dot pl which I have already saved.
06:48 Type the following code as displayed on the screen in your commonfunctions dot pl file. Let us understand the code now.
06:57 Here, we can see a collection of commonly used functions.
07:01 The first function, square(), returns the square of a number.
07:06 The second function, square underscore root(), returns the square root of a given number.
07:12 Next function, random underscore number(), generates a random number.
07:18 The last function random underscore range(), generates a random number between a lower range and upper range of numbers.
07:26 Note that we need the 1 semicolon (1;) at the end of the file.
07:31 This is because Perl needs the last expression in the file to return a true value.
07:37 Now, press Ctrl+S to save the file.
07:41 Next, we will write a Perl program in which we’ll call these subroutines using "require" method.
07:48 Let me open the sample program callprogram dot pl which I have already saved.
07:54 Type the following code as displayed on the screen in your file. Let me explain the code now.
08:02 require reads the commonfunctions dot pl file, containing Perl code, and compiles it.
08:09 This program gives 4 options to the user. The user has to choose one option at a time.
08:17 1: (one) is to find the square of a number.
08:20 2: Two is for square root of a number.
08:23 3: Three is for a random number in the given range. 4: Four is to quit the program.
08:29 If option 1 (one) is typed, it will ask the user to enter a number.
08:34 The value is stored in $number. The value is passed to the function square() in commonfunctions dot pl file.
08:44 The function returns the square of a number.
08:47 The print statement prints the square of a number as output.
08:52 If option 2 (two) is typed, the square root of a number is displayed as output.
08:58 The execution is followed as explained in the previous function square().
09:03 If option 3 (three) is typed, a random number is displayed as output in the given range.
09:09 Else, if option is 4 (four), the program exits. If any option other than the ones specified is given, the print statement says “Incorrect option”.
09:20 Note that in this program, we have called only three functions out of four from commonfunctions dot pl.
09:28 Now, press Ctrl+S to save the file.
09:31 Let us execute the program.
09:34 Switch back to the terminal and type: perl callprogram dot pl.
09:41 Observe the output.
09:44 I'll execute the program once again with a different option.
09:49 Type: perl callprogram dot pl.
09:53 Now, enter the option as 3.
09:56 Enter a lower range as 50.
09:59 Enter a upper range as 99.
10:02 We can see the random number is generated in the given range of numbers.
10:08 Try other options on your own.
10:11 This brings us to the end of this tutorial. Let us summarize.
10:16 In this tutorial, we learnt to use:

do use require methods in PERL programming.

10:24 Note: "use" module is recommended over "require" module, because it determines module availability at compile time.
10:33 Here is an assignment for you. Write a Perl program reminder.pl where you will write a letter to the participants.
10:41 Prompt the user to enter To and From name.
10:45 Call the subroutines from Letter dot pm using ‘use’ method.
10:50 Write the below functions in Letter dot pm file.
10:54 LetterDate() function returns the current date and time.
10:58 To() function returns the names of the participants.
11:02 From() function returns the sender's name.
11:05 Lettermsg() function returns the contents of the letter.
11:09 Thanksmsg() function returns "thanks" and "regards".
11:13 The output should be displayed as shown here.
11:20 The video at the following link summarizes the spoken tutotial project. Please download and watch it.
11:27 The Spoken Tutorial Project team:

conducts workshops using spoken tutorials and gives certificates on passing online tests.

11:36 For more details, please write to us.
11:40 Spoken Tutorial project is funded by NMEICT, MHRD, Government of India.

More information on this mission is available at this link.

11:51 This is Nirmala Venkat from IIT Bombay, signing off. Thanks for watching.

Contributors and Content Editors

PoojaMoolya, Sandhya.np14