Difference between revisions of "PERL/C2/Array-functions/English-timed"

From Script | Spoken-Tutorial
Jump to: navigation, search
Line 1: Line 1:
 
{| border=1
 
{| border=1
!  <center>'''Time'''</center>
+
|'''Time'''
!  <center>'''Narration'''</center>
+
|'''Narration'''
 
   
 
   
 
|-
 
|-
| 00.01
+
| 00:01
 
|Welcome to the spoken tutorial on '''Array Functions''' in '''Perl'''
 
|Welcome to the spoken tutorial on '''Array Functions''' in '''Perl'''
  
 
|-
 
|-
| 00.06
+
| 00:06
 
| In this tutorial, we will learn about '''Array functions''' in '''Perl''', like  
 
| In this tutorial, we will learn about '''Array functions''' in '''Perl''', like  
  
 
|-
 
|-
|00.11
+
|00:11
 
|'''push '''
 
|'''push '''
 
   
 
   
 
|-
 
|-
|00.11
+
|00:11
 
| '''pop'''  
 
| '''pop'''  
 
    
 
    
 
|-
 
|-
|00.12
+
|00:12
 
|'''shift'''
 
|'''shift'''
 
   
 
   
 
|-
 
|-
| 00.14
+
| 00:14
 
| '''unshift '''
 
| '''unshift '''
  
 
|-
 
|-
| 00.15
+
| 00:15
 
|'''split'''
 
|'''split'''
  
 
|-
 
|-
| 00.16
+
| 00:16
 
| '''splice '''
 
| '''splice '''
  
 
|-
 
|-
| 00.17
+
| 00:17
 
| and ''' join'''
 
| and ''' join'''
  
 
|-
 
|-
| 00.18
+
| 00:18
 
| '''sort'''
 
| '''sort'''
  
 
|-
 
|-
| 00.19
+
| 00:19
 
| '''qw'''
 
| '''qw'''
  
 
|-
 
|-
|00.20
+
|00:20
 
|I am using ''' Ubuntu Linux12.04''' operating system and '''Perl 5.14.2'''
 
|I am using ''' Ubuntu Linux12.04''' operating system and '''Perl 5.14.2'''
 
   
 
   
 
|-
 
|-
|00.28
+
|00:28
 
|I will also be using the '''gedit''' Text Editor.  
 
|I will also be using the '''gedit''' Text Editor.  
 
   
 
   
 
|-
 
|-
| 00.32
+
| 00:32
 
| You can use any text editor of your choice.  
 
| You can use any text editor of your choice.  
 
   
 
   
 
|-
 
|-
|00.36
+
|00:36
 
|You should have basic knowledge of ''' Variables,  Data Structures'''  and  '''Arrays''' in '''Perl'''
 
|You should have basic knowledge of ''' Variables,  Data Structures'''  and  '''Arrays''' in '''Perl'''
  
 
|-
 
|-
|00.43
+
|00:43
 
|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.48
+
|00:48
 
|Please go through the relevant spoken tutorials on the '''spoken tutorial''' website.  
 
|Please go through the relevant spoken tutorials on the '''spoken tutorial''' website.  
  
 
|-
 
|-
|00.54
+
|00:54
 
|'''Perl'''  provides certain inbuilt '''functions.'''   
 
|'''Perl'''  provides certain inbuilt '''functions.'''   
  
 
|-
 
|-
|00.57
+
|00:57
 
|These '''functions''' can perform various operations on an '''Array. '''
 
|These '''functions''' can perform various operations on an '''Array. '''
  
 
|-
 
|-
| 01.02
+
| 01:02
 
| Let us first learn how to add and remove elements from last position of an '''Array'''.  
 
| Let us first learn how to add and remove elements from last position of an '''Array'''.  
  
 
|-
 
|-
|01.08
+
|01:08
 
|'This can be done by using;  
 
|'This can be done by using;  
  
 
|-
 
|-
|01.10
+
|01:10
 
| '''push function''' which adds an element at the last position of an '''Array'''  
 
| '''push function''' which adds an element at the last position of an '''Array'''  
 
   
 
   
 
|-
 
|-
|01.15
+
|01:15
 
|and ''' pop function''' which removes an element from the last position of an '''Array'''  
 
|and ''' pop function''' which removes an element from the last position of an '''Array'''  
  
 
|-
 
|-
|01.21
+
|01:21
 
| Let us understand '''push''' and '''pop functions''' by using a sample program.  
 
| Let us understand '''push''' and '''pop functions''' by using a sample program.  
 
   
 
   
 
|-
 
|-
|01.26
+
|01:26
 
|Open the terminal and type ''' gedit perlArray dot pl space ampersand '''
 
|Open the terminal and type ''' gedit perlArray dot pl space ampersand '''
 
   
 
   
 
|-
 
|-
|01.33
+
|01:33
 
| And Press ''' Enter '''
 
| And Press ''' Enter '''
  
 
|-
 
|-
| 01.36
+
| 01:36
 
|This will open ''' perlArray dot pl''' file in '''gedit'''.
 
|This will open ''' perlArray dot pl''' file in '''gedit'''.
  
 
|-
 
|-
|01.41
+
|01:41
 
|Type the code as shown on the screen  
 
|Type the code as shown on the screen  
 
   
 
   
 
|-
 
|-
|01.45
+
|01:45
 
| Here, we have declared an '''Array''' of length 3.  
 
| Here, we have declared an '''Array''' of length 3.  
  
 
|-
 
|-
| 01.50
+
| 01:50
 
| '''push function''' will insert an element at the last position of this '''Array''' i.e after 3;  
 
| '''push function''' will insert an element at the last position of this '''Array''' i.e after 3;  
 
   
 
   
 
|-
 
|-
|01.57
+
|01:57
 
|whereas, ''' pop function''' will remove an element from the last position of the '''Array'''.  
 
|whereas, ''' pop function''' will remove an element from the last position of the '''Array'''.  
 
   
 
   
 
|-
 
|-
|02.04
+
|02:04
 
|In our case, 4 will be removed from the '''Array'''.  
 
|In our case, 4 will be removed from the '''Array'''.  
 
   
 
   
 
|-
 
|-
|02.08
+
|02:08
 
|Press '''Ctrl + S''' to save the file.  
 
|Press '''Ctrl + S''' to save the file.  
 
   
 
   
 
|-
 
|-
|02.11
+
|02:11
 
|'''push function''' takes 2 '''arguments'''-  
 
|'''push function''' takes 2 '''arguments'''-  
 
   
 
   
 
|-
 
|-
|02.14
+
|02:14
 
|'''1st argument''' to the '''push function''', is the '''Array''' in which to add an '''element'''.  
 
|'''1st argument''' to the '''push function''', is the '''Array''' in which to add an '''element'''.  
  
 
|-
 
|-
|02.20
+
|02:20
 
|''' 2nd argument'''  is the '''element''' which is to be '''pushed''' into the '''Array'''.  
 
|''' 2nd argument'''  is the '''element''' which is to be '''pushed''' into the '''Array'''.  
  
 
|-
 
|-
|02.25
+
|02:25
 
| The syntax of ''' pop function''' is as follows -  
 
| The syntax of ''' pop function''' is as follows -  
  
 
|-
 
|-
|02.29
+
|02:29
 
|''' pop function''' takes only one '''argument '''
 
|''' pop function''' takes only one '''argument '''
 
   
 
   
 
|-
 
|-
|02.32
+
|02:32
 
|It is the '''Array''' from which an '''element''' needs to be removed.  
 
|It is the '''Array''' from which an '''element''' needs to be removed.  
 
   
 
   
 
|-
 
|-
|02.36
+
|02:36
 
|Note: Both these functions work at ''' last position''' of an '''Array'''.  
 
|Note: Both these functions work at ''' last position''' of an '''Array'''.  
  
 
|-
 
|-
|02.41
+
|02:41
 
|The '''element''' removed by ''' pop function''' can be collected into another '''variable'''.
 
|The '''element''' removed by ''' pop function''' can be collected into another '''variable'''.
  
 
|-
 
|-
|02.46
+
|02:46
 
|The syntax for this is '''  $variable space = space pop open bracket @myArray close bracket '''
 
|The syntax for this is '''  $variable space = space pop open bracket @myArray close bracket '''
  
 
|-
 
|-
|02.57
+
|02:57
 
|Now switch to the terminal and execute the '''Perl script'''.  
 
|Now switch to the terminal and execute the '''Perl script'''.  
  
 
|-
 
|-
|03.01
+
|03:01
 
|Type '''perl perlArray dot pl''' and press '''Enter.'''
 
|Type '''perl perlArray dot pl''' and press '''Enter.'''
 
   
 
   
 
|-
 
|-
|  03.07
+
|  03:07
 
| The output is as shown on the terminal.
 
| The output is as shown on the terminal.
 
   
 
   
 
|-
 
|-
| 03.11
+
| 03:11
 
| Now, let us see how to add/remove an '''element''' from the ''' 1st position''' of an ''' Array'''.
 
| Now, let us see how to add/remove an '''element''' from the ''' 1st position''' of an ''' Array'''.
 
   
 
   
 
|-
 
|-
| 03.18
+
| 03:18
 
|This can be achieved using-  
 
|This can be achieved using-  
 
   
 
   
 
|-
 
|-
|03.20
+
|03:20
 
|''' unshift function''' - which adds an '''element''' to an '''Array''' at the 1st position  
 
|''' unshift function''' - which adds an '''element''' to an '''Array''' at the 1st position  
 
   
 
   
 
|-
 
|-
|03.25
+
|03:25
 
|''' shift function''' - which removes the first '''element''' from an '''Array'''.  
 
|''' shift function''' - which removes the first '''element''' from an '''Array'''.  
 
   
 
   
 
|-
 
|-
|  03.31
+
|  03:31
 
|Let us understand this using a sample program.  
 
|Let us understand this using a sample program.  
 
   
 
   
 
|-
 
|-
|03.35
+
|03:35
 
|I will open ''' perlArray dot pl''' file which I have already created.  
 
|I will open ''' perlArray dot pl''' file which I have already created.  
 
   
 
   
 
|-
 
|-
|  03.39
+
|  03:39
 
| Type the following piece of code as shown on the screen.  
 
| Type the following piece of code as shown on the screen.  
 
   
 
   
 
|-
 
|-
|  03.43
+
|  03:43
 
|  ''' unshift''' function will insert an '''element''' at the first position i.e before 1  
 
|  ''' unshift''' function will insert an '''element''' at the first position i.e before 1  
 
   
 
   
 
|-
 
|-
|  03.52
+
|  03:52
 
| '''shift'''  function will remove an ''' element''' from the first position.  
 
| '''shift'''  function will remove an ''' element''' from the first position.  
 
   
 
   
 
|-
 
|-
| 03.57
+
| 03:57
 
| In our case, ''' zero''' will be removed.  
 
| In our case, ''' zero''' will be removed.  
  
 
|-
 
|-
| 04.00
+
| 04:00
 
| Press '''Ctrl + S''' to save the file.  
 
| Press '''Ctrl + S''' to save the file.  
  
 
|-
 
|-
|04.03
+
|04:03
 
|The ''' unshift function''' takes 2  '''arguments '''-  
 
|The ''' unshift function''' takes 2  '''arguments '''-  
 
   
 
   
 
|-
 
|-
|04.06
+
|04:06
 
|'''1st argument''' is the '''Array''' in which to add an '''element'''  
 
|'''1st argument''' is the '''Array''' in which to add an '''element'''  
  
 
|-
 
|-
|04.10
+
|04:10
 
|''' 2nd argument''' is the '''element''' to be added into the '''Array '''
 
|''' 2nd argument''' is the '''element''' to be added into the '''Array '''
  
 
|-
 
|-
|04.15
+
|04:15
 
|''' shift function''' takes only one '''argument''' -  
 
|''' shift function''' takes only one '''argument''' -  
  
 
|-
 
|-
|04.18
+
|04:18
 
|This is the '''Array''' from which the '''element ''' needs to be removed.  
 
|This is the '''Array''' from which the '''element ''' needs to be removed.  
 
   
 
   
 
|-
 
|-
| 04.22
+
| 04:22
 
| ''' Note:''' Both these functions works at '''first position''' of an '''Array'''.  
 
| ''' Note:''' Both these functions works at '''first position''' of an '''Array'''.  
  
 
|-
 
|-
| 04.27
+
| 04:27
 
| We can collect the '''element''' removed by '''shift function''' into some variable.  
 
| We can collect the '''element''' removed by '''shift function''' into some variable.  
 
   
 
   
 
|-
 
|-
|04.33
+
|04:33
 
|This syntax for this is  ''' - $variable space =  space shift open bracket @myArray close bracket '''
 
|This syntax for this is  ''' - $variable space =  space shift open bracket @myArray close bracket '''
 
   
 
   
 
|-
 
|-
|04.44
+
|04:44
 
|Then switch to the terminal and execute the ''' Perl script'''.  
 
|Then switch to the terminal and execute the ''' Perl script'''.  
 
   
 
   
 
|-
 
|-
|04.48
+
|04:48
 
|Type ''' perl perlArray dot pl''' and press '''Enter'''.
 
|Type ''' perl perlArray dot pl''' and press '''Enter'''.
 
   
 
   
 
|-
 
|-
|04.54
+
|04:54
 
|The output displayed on the terminal is as highlighted.  
 
|The output displayed on the terminal is as highlighted.  
 
   
 
   
 
|-
 
|-
|04.59
+
|04:59
 
|Now, let us see how to remove an ''' element''' from a specified position of an '''Array.'''  
 
|Now, let us see how to remove an ''' element''' from a specified position of an '''Array.'''  
  
 
|-
 
|-
|05.05
+
|05:05
 
|''' splice function''' removes an ''' element''' from a specified position of an '''Array'''.  
 
|''' splice function''' removes an ''' element''' from a specified position of an '''Array'''.  
  
 
|-
 
|-
|05.11
+
|05:11
 
|The ''' return value''' of this '''function''' is an ''' Array''' of removed elements.  
 
|The ''' return value''' of this '''function''' is an ''' Array''' of removed elements.  
  
 
|-
 
|-
|05.17
+
|05:17
 
|Let us understand this using a sample program.  
 
|Let us understand this using a sample program.  
  
 
|-
 
|-
|  05.21
+
|  05:21
 
|Go to the ''' perlArray dot pl ''' file, which we created earlier.  
 
|Go to the ''' perlArray dot pl ''' file, which we created earlier.  
  
 
|-
 
|-
|  05.26
+
|  05:26
 
| Type the piece of code as shown on the screen.  
 
| Type the piece of code as shown on the screen.  
  
 
|-
 
|-
|05.30
+
|05:30
 
| We need to provide ''' index'''  from where we want to remove the ''' elements''' and  
 
| We need to provide ''' index'''  from where we want to remove the ''' elements''' and  
 
   
 
   
 
|-
 
|-
|  05.35
+
|  05:35
 
| the ''' offset''' upto which we want to remove the '''elements '''
 
| the ''' offset''' upto which we want to remove the '''elements '''
 
   
 
   
 
|-
 
|-
| 05.39
+
| 05:39
 
| In our case, the '''elements''' 5 and 6 will be removed.  
 
| In our case, the '''elements''' 5 and 6 will be removed.  
  
 
|-
 
|-
|  05.44
+
|  05:44
 
| Then switch to the ''' terminal'''  and execute the ''' Perl script''' by typing -  
 
| Then switch to the ''' terminal'''  and execute the ''' Perl script''' by typing -  
  
 
|-
 
|-
|  05.49
+
|  05:49
 
| ''' perl perlArray dot pl''' and press '''Enter.'''
 
| ''' perl perlArray dot pl''' and press '''Enter.'''
  
 
|-
 
|-
|05.55
+
|05:55
 
|The output is as shown on the terminal
 
|The output is as shown on the terminal
 
   
 
   
 
|-
 
|-
|  05.59
+
|  05:59
 
| Now let us look at few other ''' inbuilt functions'''  of '''Arrays.'''
 
| Now let us look at few other ''' inbuilt functions'''  of '''Arrays.'''
 
   
 
   
 
|-
 
|-
|  06.04
+
|  06:04
 
|  ''' split function''' is used to divide a '''string''' at a specified '''delimiter. '''
 
|  ''' split function''' is used to divide a '''string''' at a specified '''delimiter. '''
  
 
|-
 
|-
|06.10
+
|06:10
 
|The return value of this ''' function''' is an '''Array'''.  
 
|The return value of this ''' function''' is an '''Array'''.  
  
 
|-
 
|-
| 06.14
+
| 06:14
 
|The ''' elements''' of this '''Array''' are the divided portions of the '''string.'''  
 
|The ''' elements''' of this '''Array''' are the divided portions of the '''string.'''  
  
 
|-
 
|-
|06.19
+
|06:19
 
| ''' join function''' joins the '''elements''' of an '''Array''' , using the specified '''delimiter. '''
 
| ''' join function''' joins the '''elements''' of an '''Array''' , using the specified '''delimiter. '''
  
 
|-
 
|-
|06.25
+
|06:25
 
|It returns a string of joined '''elements.'''  
 
|It returns a string of joined '''elements.'''  
  
 
|-
 
|-
| 06.28
+
| 06:28
 
| ''' sort function''' sorts an '''Array''' in alphabetical/numerical order.  
 
| ''' sort function''' sorts an '''Array''' in alphabetical/numerical order.  
  
 
|-
 
|-
| 06.34
+
| 06:34
 
| ''' qw function ''' returns an '''Array''' of words, separated by a '''white space'''.
 
| ''' qw function ''' returns an '''Array''' of words, separated by a '''white space'''.
  
 
|-
 
|-
|  06.40
+
|  06:40
 
| Now let us understand all these ''' functions''' using a sample program.  
 
| Now let us understand all these ''' functions''' using a sample program.  
  
 
|-
 
|-
|  06.45
+
|  06:45
 
|Switch to ''' terminal''' and type  
 
|Switch to ''' terminal''' and type  
  
 
|-
 
|-
|06.48
+
|06:48
 
| ''' gedit arrayFunctions dot pl space ampersand and Press Enter'''
 
| ''' gedit arrayFunctions dot pl space ampersand and Press Enter'''
 
   
 
   
 
|-
 
|-
|06.55
+
|06:55
 
|Type the following piece of code as shown on screen.
 
|Type the following piece of code as shown on screen.
 
   
 
   
 
|-
 
|-
|07.00
+
|07:00
 
|In this case, each word of the ''' variable string''' will become an ''' element''' of an '''Array'''
 
|In this case, each word of the ''' variable string''' will become an ''' element''' of an '''Array'''
 
 
 
 
 
|-
 
|-
|07.07
+
|07:07
 
| Here, each '''element''' of '''newArray''' will be joined by '''comma'''.
 
| Here, each '''element''' of '''newArray''' will be joined by '''comma'''.
  
 
|-
 
|-
|07.12
+
|07:12
 
|''' sort function''' will sort the '''elements''' of  an '''Array''' in alphabetical order.  
 
|''' sort function''' will sort the '''elements''' of  an '''Array''' in alphabetical order.  
  
 
|-
 
|-
|07.19
+
|07:19
 
| '''qw function''' creates an '''Array''' of words separated by space.
 
| '''qw function''' creates an '''Array''' of words separated by space.
  
 
|-
 
|-
|07.25
+
|07:25
 
| Let us understand each '''function.'''
 
| Let us understand each '''function.'''
 
   
 
   
 
|-
 
|-
|07.28
+
|07:28
 
|'''split function''' takes two '''arguments'''.
 
|'''split function''' takes two '''arguments'''.
  
 
|-
 
|-
|07.31
+
|07:31
 
|''' 1st argument'''  is the ''' delimiter''' by which the ''' string''' needs to be split  
 
|''' 1st argument'''  is the ''' delimiter''' by which the ''' string''' needs to be split  
  
 
|-
 
|-
|07.36
+
|07:36
 
|''' 2nd''' is the '''string''' which needs to be split.  
 
|''' 2nd''' is the '''string''' which needs to be split.  
  
 
|-
 
|-
|07.39
+
|07:39
 
|'''Delimiters''' can be specified in ''' forward slash, single or double quotes. '''
 
|'''Delimiters''' can be specified in ''' forward slash, single or double quotes. '''
  
 
|-
 
|-
|07.45
+
|07:45
 
|''' join function''' takes 2 '''arguments'''.
 
|''' join function''' takes 2 '''arguments'''.
  
 
|-
 
|-
|07.48
+
|07:48
 
|1st is the '''delimiter''' by which the '''Array elements''' needs to be joined.   
 
|1st is the '''delimiter''' by which the '''Array elements''' needs to be joined.   
  
 
|-
 
|-
|07.53
+
|07:53
 
|2nd is the '''Array.'''  
 
|2nd is the '''Array.'''  
  
 
|-
 
|-
|07.55
+
|07:55
 
|'''Delimiters'''  can be specified in '''single or double quotes. '''
 
|'''Delimiters'''  can be specified in '''single or double quotes. '''
  
 
|-
 
|-
|07.58
+
|07:58
 
| ''' sort function''' takes a single '''argument''' , which is the '''Array''' that needs to be sorted.  
 
| ''' sort function''' takes a single '''argument''' , which is the '''Array''' that needs to be sorted.  
  
 
|-
 
|-
|08.05
+
|08:05
 
|''' qw function''' returns an ''' Array''' of words, separated by ''' space.'''
 
|''' qw function''' returns an ''' Array''' of words, separated by ''' space.'''
  
 
|-
 
|-
|08.11
+
|08:11
 
|It is not necessary to specify the word in ''' quotes''' , if written using '''qw. '''
 
|It is not necessary to specify the word in ''' quotes''' , if written using '''qw. '''
  
 
|-
 
|-
|08.17
+
|08:17
 
|Then switch to the terminal and execute the ''' Perl script''' by typing -  
 
|Then switch to the terminal and execute the ''' Perl script''' by typing -  
  
 
|-
 
|-
|08.23
+
|08:23
 
|''' perl arrayFunctions dot pl'''
 
|''' perl arrayFunctions dot pl'''
  
 
|-
 
|-
|08.26
+
|08:26
 
|and press '''Enter.'''
 
|and press '''Enter.'''
  
 
|-
 
|-
|08.29
+
|08:29
 
|The following output is displayed on the screen.
 
|The following output is displayed on the screen.
  
 
|-
 
|-
|08.33
+
|08:33
 
|Let us summarize.  
 
|Let us summarize.  
  
 
|-
 
|-
|08.34
+
|08:34
 
|In this tutorial, we have learnt to -  
 
|In this tutorial, we have learnt to -  
  
 
|-
 
|-
|08.36
+
|08:36
 
|add/remove ''' elements'''  from an '''Array '''
 
|add/remove ''' elements'''  from an '''Array '''
  
 
|-
 
|-
|08.40
+
|08:40
 
|basic functions which can be performed on '''Array'''  using sample programs  
 
|basic functions which can be performed on '''Array'''  using sample programs  
  
 
|-
 
|-
|08.46
+
|08:46
 
|Here is assignment for you -   
 
|Here is assignment for you -   
  
 
|-
 
|-
|08.48
+
|08:48
 
|'script.spoken-tutorial.org/index.php/Perl'   
 
|'script.spoken-tutorial.org/index.php/Perl'   
  
 
|-
 
|-
|08.54
+
|08:54
 
|split the above ''' string at '/ ' ''' (forward slash)  '''delimiter '''
 
|split the above ''' string at '/ ' ''' (forward slash)  '''delimiter '''
  
 
|-
 
|-
|08.59
+
|08:59
 
|Add ''' https:// '''  at the start of an newly created '''Array'''   
 
|Add ''' https:// '''  at the start of an newly created '''Array'''   
  
 
|-
 
|-
|09.06
+
|09:06
 
|Remove ''' element “Perl” ''' from the '''Array '''
 
|Remove ''' element “Perl” ''' from the '''Array '''
  
 
|-
 
|-
|09.09
+
|09:09
 
|Declare number '''Array ''' and sort it  
 
|Declare number '''Array ''' and sort it  
  
 
|-
 
|-
|09.12
+
|09:12
 
|Watch the video available at the following link
 
|Watch the video available at the following link
 
   
 
   
 
|-
 
|-
|09.15
+
|09:15
 
|It summaries the Spoken Tutorial project
 
|It summaries the Spoken Tutorial project
 
   
 
   
 
|-
 
|-
|09.19
+
|09:19
 
|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
 
   
 
   
 
|-
 
|-
| 09.24
+
| 09:24
 
|  The Spoken Tutorial Project Team  Conducts workshops using spoken tutorials
 
|  The Spoken Tutorial Project Team  Conducts workshops using spoken tutorials
 
   
 
   
 
|-
 
|-
|09.30
+
|09:30
 
|Gives certificates to those who pass an online  test
 
|Gives certificates to those who pass an online  test
 
   
 
   
 
|-
 
|-
|09.34
+
|09:34
 
|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
 
   
 
   
 
|-
 
|-
| 09.40
+
| 09:40
 
|  Spoken Tutorial Project is a part of the Talk to a  Teacher project
 
|  Spoken Tutorial Project is a part of the Talk to a  Teacher project
 
   
 
   
 
|-
 
|-
|09.44
+
|09:44
 
|It is supported by the National Mission on Education through ICT, MHRD, Government of India.
 
|It is supported by the National Mission on Education through ICT, MHRD, Government of India.
 
   
 
   
 
|-
 
|-
|09.51
+
|09:51
 
|More information on this Mission is available at spoken hyphen tutorial dot org slash NMEICT hyphen Intro
 
|More information on this Mission is available at spoken hyphen tutorial dot org slash NMEICT hyphen Intro
 
   
 
   
 
|-
 
|-
| 10.02
+
| 10:02
 
|  Hope you enjoyed this Perl tutorial.  
 
|  Hope you enjoyed this Perl tutorial.  
 
   
 
   
 
|-
 
|-
|10.04
+
|10:04
 
|This is Amol signing off.
 
|This is Amol signing off.
 
   
 
   
 
|-
 
|-
|10.06
+
|10:06
 
|Thanks for joining.
 
|Thanks for joining.
 
   
 
   
 
|}
 
|}

Revision as of 11:27, 10 July 2014

Time Narration
00:01 Welcome to the spoken tutorial on Array Functions in Perl
00:06 In this tutorial, we will learn about Array functions in Perl, like
00:11 push
00:11 pop
00:12 shift
00:14 unshift
00:15 split
00:16 splice
00:17 and join
00:18 sort
00:19 qw
00:20 I am using Ubuntu Linux12.04 operating system and Perl 5.14.2
00:28 I will also be using the gedit Text Editor.
00:32 You can use any text editor of your choice.
00:36 You should have basic knowledge of Variables, Data Structures and Arrays in Perl
00:43 Knowledge of Comments, loops and conditional statements will be an added advantage.
00:48 Please go through the relevant spoken tutorials on the spoken tutorial website.
00:54 Perl provides certain inbuilt functions.
00:57 These functions can perform various operations on an Array.
01:02 Let us first learn how to add and remove elements from last position of an Array.
01:08 'This can be done by using;
01:10 push function which adds an element at the last position of an Array
01:15 and pop function which removes an element from the last position of an Array
01:21 Let us understand push and pop functions by using a sample program.
01:26 Open the terminal and type gedit perlArray dot pl space ampersand
01:33 And Press Enter
01:36 This will open perlArray dot pl file in gedit.
01:41 Type the code as shown on the screen
01:45 Here, we have declared an Array of length 3.
01:50 push function will insert an element at the last position of this Array i.e after 3;
01:57 whereas, pop function will remove an element from the last position of the Array.
02:04 In our case, 4 will be removed from the Array.
02:08 Press Ctrl + S to save the file.
02:11 push function takes 2 arguments-
02:14 1st argument to the push function, is the Array in which to add an element.
02:20 2nd argument is the element which is to be pushed into the Array.
02:25 The syntax of pop function is as follows -
02:29 pop function takes only one argument
02:32 It is the Array from which an element needs to be removed.
02:36 Note: Both these functions work at last position of an Array.
02:41 The element removed by pop function can be collected into another variable.
02:46 The syntax for this is $variable space = space pop open bracket @myArray close bracket
02:57 Now switch to the terminal and execute the Perl script.
03:01 Type perl perlArray dot pl and press Enter.
03:07 The output is as shown on the terminal.
03:11 Now, let us see how to add/remove an element from the 1st position of an Array.
03:18 This can be achieved using-
03:20 unshift function - which adds an element to an Array at the 1st position
03:25 shift function - which removes the first element from an Array.
03:31 Let us understand this using a sample program.
03:35 I will open perlArray dot pl file which I have already created.
03:39 Type the following piece of code as shown on the screen.
03:43 unshift function will insert an element at the first position i.e before 1
03:52 shift function will remove an element from the first position.
03:57 In our case, zero will be removed.
04:00 Press Ctrl + S to save the file.
04:03 The unshift function takes 2 arguments -
04:06 1st argument is the Array in which to add an element
04:10 2nd argument is the element to be added into the Array
04:15 shift function takes only one argument -
04:18 This is the Array from which the element needs to be removed.
04:22 Note: Both these functions works at first position of an Array.
04:27 We can collect the element removed by shift function into some variable.
04:33 This syntax for this is - $variable space = space shift open bracket @myArray close bracket
04:44 Then switch to the terminal and execute the Perl script.
04:48 Type perl perlArray dot pl and press Enter.
04:54 The output displayed on the terminal is as highlighted.
04:59 Now, let us see how to remove an element from a specified position of an Array.
05:05 splice function removes an element from a specified position of an Array.
05:11 The return value of this function is an Array of removed elements.
05:17 Let us understand this using a sample program.
05:21 Go to the perlArray dot pl file, which we created earlier.
05:26 Type the piece of code as shown on the screen.
05:30 We need to provide index from where we want to remove the elements and
05:35 the offset upto which we want to remove the elements
05:39 In our case, the elements 5 and 6 will be removed.
05:44 Then switch to the terminal and execute the Perl script by typing -
05:49 perl perlArray dot pl and press Enter.
05:55 The output is as shown on the terminal
05:59 Now let us look at few other inbuilt functions of Arrays.
06:04 split function is used to divide a string at a specified delimiter.
06:10 The return value of this function is an Array.
06:14 The elements of this Array are the divided portions of the string.
06:19 join function joins the elements of an Array , using the specified delimiter.
06:25 It returns a string of joined elements.
06:28 sort function sorts an Array in alphabetical/numerical order.
06:34 qw function returns an Array of words, separated by a white space.
06:40 Now let us understand all these functions using a sample program.
06:45 Switch to terminal and type
06:48 gedit arrayFunctions dot pl space ampersand and Press Enter
06:55 Type the following piece of code as shown on screen.
07:00 In this case, each word of the variable string will become an element of an Array
07:07 Here, each element of newArray will be joined by comma.
07:12 sort function will sort the elements of an Array in alphabetical order.
07:19 qw function creates an Array of words separated by space.
07:25 Let us understand each function.
07:28 split function takes two arguments.
07:31 1st argument is the delimiter by which the string needs to be split
07:36 2nd is the string which needs to be split.
07:39 Delimiters can be specified in forward slash, single or double quotes.
07:45 join function takes 2 arguments.
07:48 1st is the delimiter by which the Array elements needs to be joined.
07:53 2nd is the Array.
07:55 Delimiters can be specified in single or double quotes.
07:58 sort function takes a single argument , which is the Array that needs to be sorted.
08:05 qw function returns an Array of words, separated by space.
08:11 It is not necessary to specify the word in quotes , if written using qw.
08:17 Then switch to the terminal and execute the Perl script by typing -
08:23 perl arrayFunctions dot pl
08:26 and press Enter.
08:29 The following output is displayed on the screen.
08:33 Let us summarize.
08:34 In this tutorial, we have learnt to -
08:36 add/remove elements from an Array
08:40 basic functions which can be performed on Array using sample programs
08:46 Here is assignment for you -
08:48 'script.spoken-tutorial.org/index.php/Perl'
08:54 split the above string at '/ ' (forward slash) delimiter
08:59 Add https:// at the start of an newly created Array
09:06 Remove element “Perl” from the Array
09:09 Declare number Array and sort it
09:12 Watch the video available at the following link
09:15 It summaries the Spoken Tutorial project
09:19 If you do not have good bandwidth, you can download and watch it
09:24 The Spoken Tutorial Project Team Conducts workshops using spoken tutorials
09:30 Gives certificates to those who pass an online test
09:34 For more details, please write to contact at spoken hyphen tutorial dot org
09:40 Spoken Tutorial Project is a part of the Talk to a Teacher project
09:44 It is supported by the National Mission on Education through ICT, MHRD, Government of India.
09:51 More information on this Mission is available at spoken hyphen tutorial dot org slash NMEICT hyphen Intro
10:02 Hope you enjoyed this Perl tutorial.
10:04 This is Amol signing off.
10:06 Thanks for joining.

Contributors and Content Editors

Gaurav, PoojaMoolya, Sandhya.np14