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