Difference between revisions of "PERL/C2/Data-Structures/English-timed"
From Script | Spoken-Tutorial
Sandhya.np14 (Talk | contribs) |
|||
Line 5: | Line 5: | ||
|- | |- | ||
| 00:00 | | 00:00 | ||
− | |Welcome to the spoken tutorial on '''Data Structures''' in '''Perl''' | + | |Welcome to the spoken tutorial on '''Data Structures''' in '''Perl'''. |
|- | |- | ||
| 00:05 | | 00:05 | ||
− | | In this tutorial, we will learn about '''Data Structures''' available in '''Perl''' | + | | In this tutorial, we will learn about '''Data Structures''' available in '''Perl'''. |
|- | |- | ||
|00:11 | |00:11 | ||
− | |Here I am using ''' Ubuntu | + | |Here I am using ''' Ubuntu Linux 12.04 ''' operating system and '''Perl 5.14.2'''. |
|- | |- | ||
Line 25: | Line 25: | ||
|- | |- | ||
| 00:25 | | 00:25 | ||
− | | You should have basic knowledge of | + | | You should have basic knowledge of variables in '''Perl'''. |
|- | |- | ||
| 00:29 | | 00:29 | ||
− | |Knowledge of ''' comments, loops''' and '''conditional statements''' will be an added advantage. | + | |Knowledge of '''comments, loops''' and '''conditional statements''' will be an added advantage. |
|- | |- | ||
| 00:36 | | 00:36 | ||
− | | Please go through the relevant spoken tutorials on the ''' | + | | Please go through the relevant spoken tutorials on the '''Spoken Tutorial''' website. |
|- | |- | ||
|00:41 | |00:41 | ||
− | |'''Perl''' | + | |'''Perl''' has 3 types of '''data structures:''' |
|- | |- | ||
Line 49: | Line 49: | ||
|- | |- | ||
|00:46 | |00:46 | ||
− | |'''Hash''' , also | + | |'''Hash''', also called as '''Associative Array'''. |
|- | |- | ||
|00:50 | |00:50 | ||
− | |'''Scalar:''' This type of '''data structure''' holds a value of any | + | |'''Scalar:''' This type of '''data structure''' holds a value of any data type. |
|- | |- | ||
|00:56 | |00:56 | ||
− | |The | + | |The data type can be '''string, number, double''' etc. |
|- | |- | ||
Line 65: | Line 65: | ||
|- | |- | ||
|01:06 | |01:06 | ||
− | | | + | |Note: Reference in '''Perl''' will be covered in subsequent tutorial. |
|- | |- | ||
Line 73: | Line 73: | ||
|- | |- | ||
|01:16 | |01:16 | ||
− | | | + | |$count = 12 semicolon. |
|- | |- | ||
|01:20 | |01:20 | ||
− | | | + | |$string = in single quote 'I am scalar of type string' semicolon. |
|- | |- | ||
|01:26 | |01:26 | ||
− | |We can perform the following operations on | + | |We can perform the following operations on scalar. |
|- | |- | ||
|01:30 | |01:30 | ||
− | |Assign a value to it | + | |Assign a value to it. |
|- | |- | ||
|01:32 | |01:32 | ||
− | |Assign one | + | |Assign one scalar to another. |
|- | |- | ||
|01:35 | |01:35 | ||
− | | | + | | Arithmetic operations on '''number''' type of scalars like add, subtract etc. |
|- | |- | ||
| 01:41 | | 01:41 | ||
− | | | + | |String operations on string scalar like '''concatenation, substr''' etc. |
|- | |- | ||
|01:48 | |01:48 | ||
− | |Now let us look at an example of | + | |Now, let us look at an example of scalar data structure. |
|- | |- | ||
|01:52 | |01:52 | ||
− | | Switch to terminal and type '''gedit scalars dot pl''' space '''&''' and press '''Enter.''' | + | | Switch to terminal and type: '''gedit scalars dot pl''' space '''&''' and press '''Enter.''' |
|- | |- | ||
| 02:01 | | 02:01 | ||
− | | This will open the | + | | This will open the 'scalars dot pl file' in '''gedit'''. |
|- | |- | ||
Line 121: | Line 121: | ||
|- | |- | ||
|02:13 | |02:13 | ||
− | |These are few | + | |These are few arithmetic operations that can be performed on '''number''' type of scalar. |
|- | |- | ||
|02:19 | |02:19 | ||
− | |These are '''string operations''' that can be performed on '''string''' type of | + | |These are '''string operations''' that can be performed on '''string''' type of scalar. |
|- | |- | ||
Line 133: | Line 133: | ||
|- | |- | ||
|02:30 | |02:30 | ||
− | | Here | + | | Here 'index 0' specifies start of a '''string''', i.e. from where we want to start extraction of the '''string.''' |
|- | |- | ||
Line 141: | Line 141: | ||
|- | |- | ||
|02:46 | |02:46 | ||
− | |Press ''' | + | |Press '''Ctrl + s''' to '''save''' the file. |
|- | |- | ||
| 02:50 | | 02:50 | ||
− | | Then switch to the terminal and execute the '''Perl script''' as | + | | Then switch to the terminal and execute the '''Perl script''' as: |
|- | |- | ||
|02:55 | |02:55 | ||
− | |''' perl scalars dot pl''' and press '''Enter''' | + | |''' perl scalars dot pl''' and press '''Enter'''. |
|- | |- | ||
|03:00 | |03:00 | ||
− | | The output shown on terminal is as highlighted | + | | The output shown on terminal is as highlighted. |
|- | |- | ||
|03:05 | |03:05 | ||
− | |Now, let us look at '''array | + | |Now, let us look at '''array''' data structure in '''PERL'''. |
|- | |- | ||
Line 169: | Line 169: | ||
|- | |- | ||
| 03:16 | | 03:16 | ||
− | | It has an '''index | + | | It has an '''index''' which is used for performing various operations on the '''array'''. |
|- | |- | ||
Line 177: | Line 177: | ||
|- | |- | ||
| 03:25 | | 03:25 | ||
− | | Unlike other programming languages, there is no need to declare an array or its length before using it in Perl. | + | | Unlike other programming languages, there is no need to declare an array or its length before using it in '''Perl'''. |
|- | |- | ||
|03:33 | |03:33 | ||
− | |'''Perl array''' | + | |'''Perl array''' stretches or shrinks as per the elements added or removed from it. |
|- | |- | ||
| 03:39 | | 03:39 | ||
− | | The syntax to write an array is | + | | The syntax to write an array is: |
|- | |- | ||
| 03:41 | | 03:41 | ||
− | |''' at the rate variableName space equal to ''' space open bracket list of elements separated with comma close bracket semicolon | + | |'''at the rate variableName space equal to ''' space open bracket list of elements separated with comma close bracket semicolon. |
|- | |- | ||
|03:54 | |03:54 | ||
− | |Now let us look at an example of '''array | + | |Now, let us look at an example of '''array''' data structure. |
|- | |- | ||
|03:57 | |03:57 | ||
− | |Switch to | + | |Switch to terminal and type: '''gedit perlArray dot pl''' space '''&''' and press '''Enter'''. |
|- | |- | ||
Line 221: | Line 221: | ||
|- | |- | ||
| 04:34 | | 04:34 | ||
− | | This example shows the various types of '''arrays''' in '''Perl. ''' | + | | This example shows the various types of '''arrays''' in '''Perl.''' |
|- | |- | ||
Line 233: | Line 233: | ||
|- | |- | ||
|04:47 | |04:47 | ||
− | |Then switch to terminal and execute the '''Perl script''' as | + | |Then switch to terminal and execute the '''Perl script''' as: |
|- | |- | ||
Line 241: | Line 241: | ||
|- | |- | ||
|04:59 | |04:59 | ||
− | |The following output is displayed on the terminal | + | |The following output is displayed on the terminal. |
|- | |- | ||
|05:04 | |05:04 | ||
− | |Now, let us look at '''Hash | + | |Now, let us look at '''Hash''' data structure in '''Perl'''. |
|- | |- | ||
| 05:08 | | 05:08 | ||
− | | '''Hash''' is alternatively called as '''Associative array''' | + | | '''Hash''' is alternatively called as '''Associative array'''. |
|- | |- | ||
| 05:12 | | 05:12 | ||
− | | It is a '''Key Value pair data structure. | + | | It is a '''Key - Value''' pair data structure. |
|- | |- | ||
Line 269: | Line 269: | ||
|- | |- | ||
|05:30 | |05:30 | ||
− | |It also holds '''value''' of any | + | |It also holds '''value''' of any data type. |
|- | |- | ||
|05:34 | |05:34 | ||
− | |The syntax of '''hash''' is | + | |The syntax of '''hash''' is: |
|- | |- | ||
Line 285: | Line 285: | ||
|- | |- | ||
|05:42 | |05:42 | ||
− | |'''single quote key | + | |'''single quote key-name single quote space equal to greater than sign space Value comma''' |
|- | |- | ||
Line 305: | Line 305: | ||
|- | |- | ||
| 06:03 | | 06:03 | ||
− | | Now let us look at an example of '''hash | + | | Now let us look at an example of '''hash''' data structure. |
|- | |- | ||
| 06:07 | | 06:07 | ||
− | | Switch to terminal and type | + | | Switch to terminal and type: |
|- | |- | ||
Line 317: | Line 317: | ||
|- | |- | ||
| 06:18 | | 06:18 | ||
− | | This will open the | + | | This will open the 'perlHash dot pl' file in '''gedit.''' |
|- | |- | ||
Line 329: | Line 329: | ||
|- | |- | ||
| 06:31 | | 06:31 | ||
− | | This example | + | | This example shows the use of '''hash'''. |
|- | |- | ||
|06:35 | |06:35 | ||
− | |Now let us see how to print the '''hash''' | + | |Now, let us see how to print the '''hash'''. |
|- | |- | ||
Line 349: | Line 349: | ||
|- | |- | ||
|06:50 | |06:50 | ||
− | |Then switch to terminal and execute the '''Perl script''' as | + | |Then switch to terminal and execute the '''Perl script''' as: |
|- | |- | ||
Line 377: | Line 377: | ||
|- | |- | ||
|07:11 | |07:11 | ||
− | |'''Hash Data Structure''' in '''Perl''' | + | |'''Hash Data Structure''' in '''Perl''', |
|- | |- | ||
Line 401: | Line 401: | ||
|- | |- | ||
|07:28 | |07:28 | ||
− | |Declare and print a '''hash''' of Employee Name and their department. | + | |Declare and print a '''hash''' of '''Employee Name''' and their '''department'''. |
|- | |- | ||
|07:33 | |07:33 | ||
− | | Hint: ''' 'Employee' =>(equal to greater than sign) 'John'''' comma | + | | Hint: ''' 'Employee' =>(equal to greater than sign) 'John' ''' comma |
|- | |- | ||
|07:38 | |07:38 | ||
− | | ''' 'Department' =>(equal to greater than sign) 'Engineering' ''' | + | | ''' 'Department' =>(equal to greater than sign) 'Engineering' '''. |
|- | |- | ||
|07:42 | |07:42 | ||
− | |Watch the video available at the following link | + | |Watch the video available at the following link. |
|- | |- | ||
|07:46 | |07:46 | ||
− | |It | + | |It summarizes the Spoken Tutorial project. |
|- | |- | ||
|07:49 | |07:49 | ||
− | |If you do not have good bandwidth, you can download and watch it | + | |If you do not have good bandwidth, you can download and watch it. |
|- | |- | ||
| 07:53 | | 07:53 | ||
− | | The Spoken Tutorial Project | + | | The Spoken Tutorial Project team: Conducts workshops using spoken tutorials. |
|- | |- | ||
|07:59 | |07:59 | ||
− | |Gives certificates to those who pass an online test | + | |Gives certificates to those who pass an online test. |
|- | |- | ||
|08:03 | |08:03 | ||
− | |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. |
|- | |- | ||
| 08:10 | | 08:10 | ||
− | | Spoken Tutorial | + | | "Spoken Tutorial" project is a part of the "Talk to a Teacher" project. |
|- | |- | ||
Line 445: | Line 445: | ||
|- | |- | ||
|08:22 | |08:22 | ||
− | |More information on this | + | |More information on this mission is available at spoken hyphen tutorial dot org slash NMEICT hyphen Intro. |
|- | |- | ||
Line 453: | Line 453: | ||
|- | |- | ||
|08:35 | |08:35 | ||
− | |This is Amol signing off. | + | |This is Amol, signing off. |
|- | |- |
Revision as of 21:41, 12 May 2015
Time | Narration |
00:00 | Welcome to the spoken tutorial on Data Structures in Perl. |
00:05 | In this tutorial, we will learn about Data Structures available in Perl. |
00:11 | Here I am using Ubuntu Linux 12.04 operating system and Perl 5.14.2. |
00:18 | I will also be using the gedit Text Editor. |
00:22 | You can use any text editor of your choice. |
00:25 | You should have basic knowledge of variables in Perl. |
00:29 | Knowledge of comments, loops and conditional statements will be an added advantage. |
00:36 | Please go through the relevant spoken tutorials on the Spoken Tutorial website. |
00:41 | Perl has 3 types of data structures: |
00:44 | Scalar |
00:45 | Array |
00:46 | Hash, also called as Associative Array. |
00:50 | Scalar: This type of data structure holds a value of any data type. |
00:56 | The data type can be string, number, double etc. |
01:01 | It can also hold the reference to an array or reference to a hash. |
01:06 | Note: Reference in Perl will be covered in subsequent tutorial. |
01:11 | Scalar type of data structure is as simple as declaring the variable. |
01:16 | $count = 12 semicolon. |
01:20 | $string = in single quote 'I am scalar of type string' semicolon. |
01:26 | We can perform the following operations on scalar. |
01:30 | Assign a value to it. |
01:32 | Assign one scalar to another. |
01:35 | Arithmetic operations on number type of scalars like add, subtract etc. |
01:41 | String operations on string scalar like concatenation, substr etc. |
01:48 | Now, let us look at an example of scalar data structure. |
01:52 | Switch to terminal and type: gedit scalars dot pl space & and press Enter. |
02:01 | This will open the 'scalars dot pl file' in gedit. |
02:05 | Type the following code as displayed on the screen. |
02:09 | This is the declaration and assignment to the scalar. |
02:13 | These are few arithmetic operations that can be performed on number type of scalar. |
02:19 | These are string operations that can be performed on string type of scalar. |
02:25 | substr is the PERL function which provides part of the string as output. |
02:30 | Here 'index 0' specifies start of a string, i.e. from where we want to start extraction of the string. |
02:39 | And 11 specify the offset upto where we want the string to be in the output. |
02:46 | Press Ctrl + s to save the file. |
02:50 | Then switch to the terminal and execute the Perl script as: |
02:55 | perl scalars dot pl and press Enter. |
03:00 | The output shown on terminal is as highlighted. |
03:05 | Now, let us look at array data structure in PERL. |
03:09 | Array: It is a list of elements. |
03:12 | Elements can be string, number etc. |
03:16 | It has an index which is used for performing various operations on the array. |
03:22 | Index starts with zero. |
03:25 | Unlike other programming languages, there is no need to declare an array or its length before using it in Perl. |
03:33 | Perl array stretches or shrinks as per the elements added or removed from it. |
03:39 | The syntax to write an array is: |
03:41 | at the rate variableName space equal to space open bracket list of elements separated with comma close bracket semicolon. |
03:54 | Now, let us look at an example of array data structure. |
03:57 | Switch to terminal and type: gedit perlArray dot pl space & and press Enter. |
04:08 | This will open the perlArray dot pl file in gedit. |
04:12 | Type the following code as displayed on the screen. |
04:18 | This is the number array which has elements of number type. |
04:23 | This is the string array which has elements of string type. |
04:29 | This array has elements of both number and string type. |
04:34 | This example shows the various types of arrays in Perl. |
04:39 | This is how we can print the array in Perl. |
04:43 | Press Ctrl + S to save the file. |
04:47 | Then switch to terminal and execute the Perl script as: |
04:52 | perl perlArray dot pl and press Enter. |
04:59 | The following output is displayed on the terminal. |
05:04 | Now, let us look at Hash data structure in Perl. |
05:08 | Hash is alternatively called as Associative array. |
05:12 | It is a Key - Value pair data structure. |
05:15 | Key in hash is unique. |
05:18 | If the same key is added again, then the value of that key will be overridden by the latest value assigned to the key. |
05:28 | Value can be duplicate. |
05:30 | It also holds value of any data type. |
05:34 | The syntax of hash is: |
05:36 | percentage variable name space equal to space open bracket |
05:41 | Press Enter |
05:42 | single quote key-name single quote space equal to greater than sign space Value comma |
05:50 | Press Enter |
05:52 | single quote key Name single quote space equal to greater than sign space Value |
05:58 | Press Enter |
06:00 | close bracket semicolon |
06:03 | Now let us look at an example of hash data structure. |
06:07 | Switch to terminal and type: |
06:10 | gedit perlHash dot pl space & and press Enter. |
06:18 | This will open the 'perlHash dot pl' file in gedit. |
06:22 | Type the following code as displayed on the screen. |
06:27 | This hash indicates the marks obtained in a subject. |
06:31 | This example shows the use of hash. |
06:35 | Now, let us see how to print the hash. |
06:38 | For now, just note the way I have printed the hash. |
06:42 | Detailed explanation will be given in subsequent tutorial. |
06:47 | Press Ctrl + S to save the file. |
06:50 | Then switch to terminal and execute the Perl script as: |
06:55 | perl perlHash dot pl and press Enter. |
07:01 | The following output is displayed on the terminal |
07:05 | Let us summarize. |
07:06 | In this tutorial, we have learnt - |
07:09 | scalar |
07:10 | Array and |
07:11 | Hash Data Structure in Perl, |
07:13 | using sample programs. |
07:15 | There is assignment for you - |
07:17 | Declare scalar variable |
07:19 | Assign value of type float to it and then print it. |
07:23 | Declare and print an array of colors 'Red', 'Yellow' and 'Green'. |
07:28 | Declare and print a hash of Employee Name and their department. |
07:33 | Hint: 'Employee' =>(equal to greater than sign) 'John' comma |
07:38 | 'Department' =>(equal to greater than sign) 'Engineering' . |
07:42 | Watch the video available at the following link. |
07:46 | It summarizes the Spoken Tutorial project. |
07:49 | If you do not have good bandwidth, you can download and watch it. |
07:53 | The Spoken Tutorial Project team: Conducts workshops using spoken tutorials. |
07:59 | Gives certificates to those who pass an online test. |
08:03 | For more details, please write to contact at spoken hyphen tutorial dot org. |
08:10 | "Spoken Tutorial" project is a part of the "Talk to a Teacher" project. |
08:15 | It is supported by the National Mission on Education through ICT, MHRD, Government of India. |
08:22 | More information on this mission is available at spoken hyphen tutorial dot org slash NMEICT hyphen Intro. |
08:33 | Hope you enjoyed this Perl tutorial. |
08:35 | This is Amol, signing off. |
08:38 | Thanks for joining. |