Difference between revisions of "PERL/C2/Variables-in-Perl/English-timed"

From Script | Spoken-Tutorial
Jump to: navigation, search
Line 161: Line 161:
 
|-
 
|-
 
|  03:49
 
|  03:49
| Now press '''Enter'''
+
| Now press '''Enter'''.
  
 
|-
 
|-
Line 169: Line 169:
 
|-
 
|-
 
|  03:56
 
|  03:56
|  Now let's execute the '''Perl''' script by typing '''perl variables dot pl''' and press '''Enter'''.
+
|  Now let us execute the '''Perl''' script by typing '''perl variables dot pl''' and press '''Enter'''.
  
 
|-
 
|-
Line 185: Line 185:
 
|-
 
|-
 
|  04:18
 
|  04:18
|  Instead of '''dollar priority equal to one;'''  type
+
|  Instead of '''dollar priority equal to one;'''  type:
  
 
|-
 
|-
 
| 04:22
 
| 04:22
| '''dollar priority equal to in single quote high '''
+
| '''dollar priority''' equal to in single quotes '''high''';
  
 
|-
 
|-
Line 197: Line 197:
 
|-
 
|-
 
| 04:34
 
| 04:34
| A '''scalar''' can hold data of any type, be it a '''string''', a number  
+
| A '''scalar''' can hold data of any type, be it a '''string''', a number.
  
 
|-
 
|-
 
|  04:38
 
|  04:38
|  Save this file and compile the script once again by typing
+
|  Save this file and compile the script once again by typing:
  
 
|-
 
|-
Line 225: Line 225:
 
|-
 
|-
 
| 05:10
 
| 05:10
| You can also use '''scalars''' within a double-quoted '''strings''' as
+
| You can also use '''scalars''' within a double-quoted '''string''' as
  
 
|-
 
|-
 
| 05:15
 
| 05:15
| '''dollar priority in double quote String'''
+
| '''dollar priority''' in double quotes '''string''';
  
 
|-
 
|-
Line 237: Line 237:
 
|-
 
|-
 
|  05:22  
 
|  05:22  
let us learn how to declare multiple '''variables'''.
+
Let us learn how to declare multiple variables.
  
 
|-
 
|-
 
| 05:27  
 
| 05:27  
| To do so open the new file in Text Editor.
+
| To do so, open the new file in Text Editor.
  
 
|-
 
|-
 
|  05:31
 
|  05:31
on'''Terminal''' type - '''gedit multivar dot pl space ampersand''' and press '''Enter'''.
+
On'''Terminal''', type'''gedit multivar dot pl space ampersand''' and press '''Enter'''.
  
 
|-
 
|-
 
| 05:42
 
| 05:42
| This will open '''multivar dot pl''' file in text editor
+
| This will open "multivar dot pl" file in text editor.
  
 
|-
 
|-
 
|  05:48
 
|  05:48
|  Now type -
+
|  Now, type:
  
 
|-
 
|-
Line 261: Line 261:
 
|-
 
|-
 
|  06:00
 
|  06:00
|  To copy the value of variable '''dollar firstVar''' to '''dollar secondVar''', type -
+
|  To copy the value of variable '''dollar firstVar''' to '''dollar secondVar''', type:
  
 
|-
 
|-
Line 269: Line 269:
 
|-
 
|-
 
|  06:19
 
|  06:19
|  All mathematical operations like addition, subtraction, multiplication, division, can be done on these variables  
+
|  All mathematical operations like addition, subtraction, multiplication, division, can be done on these variables.
  
 
|-
 
|-
Line 289: Line 289:
 
|-
 
|-
 
|  06:51
 
|  06:51
|  Now to print these values, type
+
|  Now to print these values, type:
  
 
|-
 
|-
 
| 06:55
 
| 06:55
| '''print double quote firstVar: dollar firstVar and secondVar: dollar secondVar slash n''' close double quote  '''semicolon''' press '''Enter'''.
+
| '''print''' double quote '''firstVar:''' dollar '''firstVar and secondVar:''' dollar '''secondVar''' slash '''n''' close double quotes  semicolon press '''Enter'''.
  
 
|-
 
|-
Line 305: Line 305:
 
|-
 
|-
 
| 07:23
 
| 07:23
| For this type
+
| For this, type:
  
 
|-
 
|-
 
| 07:25
 
| 07:25
| '''dollar addition space equal to space dollar firstVar plus space dollar secondVar semicolon'''and Press '''Enter'''.
+
| dollar '''addition''' space equal to space dollar '''firstVar''' space plus space dollar '''secondVar''' semicolon and Press '''Enter'''.
  
 
|-
 
|-
Line 317: Line 317:
 
|-
 
|-
 
|  07:47  
 
|  07:47  
|  Once again, to print the value of the  variable '''addition''', type
+
|  Once again, to print the value of the  variable '''addition''', type:
  
 
|-
 
|-
 
| 07:53
 
| 07:53
| '''print double quote Addition is dollar addition slash n''' close double quote '''semicolon'''
+
| '''print double quote Addition is dollar addition slash n''' close double quote semicolon.
  
 
|-
 
|-
Line 329: Line 329:
 
|-
 
|-
 
|  08:07
 
|  08:07
|  To compile this file again on terminal type
+
|  To compile this file, again on terminal type:
  
 
|-
 
|-
Line 337: Line 337:
 
|-
 
|-
 
| 08:18
 
| 08:18
| There is no syntax error so we can execute the script...
+
| There is no syntax error, so we can execute the script
  
 
|-
 
|-
 
|  08:24
 
|  08:24
|   by typing '''perl multivar dot pl'''
+
| by typing '''perl multivar dot pl'''
  
 
|-
 
|-
Line 373: Line 373:
 
|-
 
|-
 
| 08:55
 
| 08:55
| So we can execute the script as '''perl multivar dot pl'''
+
| So, we can execute the script as '''perl multivar dot pl'''
  
 
|-
 
|-
Line 385: Line 385:
 
|-
 
|-
 
| 09:11
 
| 09:11
| In this tutorial we have learnt,
+
| In this tutorial, we have learnt  
  
 
|-
 
|-
 
| 09:14
 
| 09:14
| To Declare and Use '''scalar variables''' in '''Perl'''
+
| to declare and use '''scalar variables''' in '''Perl'''.
  
 
|-
 
|-
 
|  09:18
 
|  09:18
'''Assignment'''
+
|  Assignment:
  
 
|-
 
|-
 
| 09:20
 
| 09:20
|  Declare a number '''variable'''.  
+
|  Declare a number variable.  
 
|-
 
|-
 
| 09:22
 
| 09:22
Line 403: Line 403:
 
|-
 
|-
 
| 09:24
 
| 09:24
|  Print the '''variable''' declared.
+
|  Print the variable declared.
 
|-
 
|-
 
| 09:26
 
| 09:26
Line 412: Line 412:
 
|-
 
|-
 
| 09:34
 
| 09:34
|  Print those '''2  variables''' one after the other.
+
|  Print those two variables one after the other.
  
 
|-
 
|-
 
| 09:38   
 
| 09:38   
|  Watch the video available at the following link  
+
|  Watch the video available at the following link.
  
 
|-
 
|-
 
| 09:42  
 
| 09:42  
| It summarises the Spoken Tutorial project  
+
| It summarizes the Spoken Tutorial project.
  
 
|-
 
|-
 
| 09:45
 
| 09:45
| 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:50
 
|  09:50
|  The Spoken Tutorial Project Team  
+
|  The Spoken Tutorial Project Team:
  
 
|-
 
|-
 
| 09:53
 
| 09:53
| Conducts workshops using spoken tutorials  
+
| Conducts workshops using spoken tutorials.
  
 
|-
 
|-
 
| 09:56
 
| 09:56
| Gives certificates to those who pass an online  test  
+
| Gives certificates to those who pass an online  test.
  
 
|-
 
|-
 
| 10:01
 
| 10:01
| For more details, please write to  contact at spoken tutorial dot org  
+
| For more details, please write to  contact at spoken tutorial dot org.
  
 
|-
 
|-
 
|  10:08
 
|  10:08
|  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.
  
 
|-
 
|-
 
| 10:13   
 
| 10:13   
|  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.
  
 
|-
 
|-
 
|  10:23
 
|  10:23
|  More information on this Mission is available  at the following link.
+
|  More information on this mission is available  at the following link.
  
 
|-
 
|-
 
|  10:29
 
|  10:29
|  Hope you enjoyed this '''Perl''' tutorial. This is Amol Brahmankar signing off.
+
|  Hope you enjoyed this '''Perl''' tutorial. This is Amol Brahmankar, signing off.
  
 
|-
 
|-

Revision as of 12:22, 7 May 2015

Time Narration
00:01 Welcome to the spoken tutorial on Variables in Perl.
00:06 In this tutorial, we will learn about variables in Perl
00:12 I am using Ubuntu Linux12.04 operating system and
00:18 Perl 5.14.2 that is: Perl revision 5, version 14, and subversion 2.
00:26 I will also be using the gedit Text Editor.
00:30 You can use any text editor of your choice.
00:34 Variables in Perl:
00:37 Variables are used for storing values like text strings, numbers or arrays.
00:44 Once a variable is declared, it can be used over and over again in the script.
00:50 Scalar represents a single value and can store scalars only.
00:56 Scalar variables are declared using $ (dollar) symbol.
01:00 Let us look at Variable Declaration:
01:03 A variable can be declared as follows: dollar priority semicolon
01:09 Variable names in Perl can have several formats. Variables must begin with a letter or underscore (_).
01:18 And may contain letters, digits, underscores or a combination of above three.
01:24 Variables declared with CAPITAL letters have special meaning in Perl.
01:30 So, avoid declaring variables using capital letters.
01:34 Now open the Terminal and type: gedit variables dot pl ampersand(&)
01:44 The ampersand will unlock the command prompt on the terminal. Now press Enter.
01:50 This will open the variables.pl file in gedit text editor.
01:56 dot pl (.pl) is the default extension of a Perl file.
02:01 Type the following in the file: dollar priority semicolon and press Enter.
02:10 So we have declared the variable priority.
02:13 You do not need to declare a variable before using it;
02:18 you can just use it into your code.
02:21 Now let us assign a numerical value to the variable priority.
02:25 For this, type: dollar priority space equal to space one semicolon
02:32 and press Enter.
02:34 Next, type:
02:36 print space double quote Value of variable is: dollar priority slash n close double quote semicolon and press Enter.
02:50 slash n is the "new line" character.
02:53 Now save this file as variables.pl at any location.
03:02 In my case, it will get saved in home/amol directory. Now save this file.
03:10 Now, let us change the permissions of variables.pl file which we just now created.
03:18 To do so, on the Terminal type, chmod 755 variables dot pl
03:27 This will provide "read", "write" & "execute" rights to the file.
03:32 To compile this Perl script, on the Terminal,
03:36 type: perl hyphen c variables dot pl
03:42 Hyphen c switch compiles the Perl script for any compilation/syntax error.
03:49 Now press Enter.
03:51 This tells us that there is no syntax error in our script.
03:56 Now let us execute the Perl script by typing perl variables dot pl and press Enter.
04:06 The output displayed is as highlighted.
04:10 We can also assign a string value to the variable we declared.
04:15 Switch back to the Text editor window.
04:18 Instead of dollar priority equal to one; type:
04:22 dollar priority equal to in single quotes high;
04:28 Please note that the assignments are evaluated from right to left.
04:34 A scalar can hold data of any type, be it a string, a number.
04:38 Save this file and compile the script once again by typing:
04:45 perl hyphen c variables dot pl now press Enter.
04:51 This tells us that there is no syntax error.
04:55 Execute the script by typing perl variables dot pl and press Enter.
05:03 The output is as shown.
05:07 Now switch back to the Text Editor window.
05:10 You can also use scalars within a double-quoted string as
05:15 dollar priority in double quotes string;
05:19 Save this file and close it.
05:22 Let us learn how to declare multiple variables.
05:27 To do so, open the new file in Text Editor.
05:31 OnTerminal, type: gedit multivar dot pl space ampersand and press Enter.
05:42 This will open "multivar dot pl" file in text editor.
05:48 Now, type:
05:50 dollar firstVar comma dollar secondVar semicolon and press Enter.
06:00 To copy the value of variable dollar firstVar to dollar secondVar, type:
06:07 dollar firstVar space equal to space dollar secondVar semicolon and press Enter.
06:19 All mathematical operations like addition, subtraction, multiplication, division, can be done on these variables.
06:30 Let us see how we can achieve this using Perl.
06:34 Switch to text editor.
06:36 And now let us assign the value 10 to both of these variables by typing,
06:41 dollar firstVar equal to dollar secondVar equal to ten semicolon And Press Enter.
06:51 Now to print these values, type:
06:55 print double quote firstVar: dollar firstVar and secondVar: dollar secondVar slash n close double quotes semicolon press Enter.
07:17 Now save this file.
07:19 Now let us add the values in the two variables.
07:23 For this, type:
07:25 dollar addition space equal to space dollar firstVar space plus space dollar secondVar semicolon and Press Enter.
07:43 Notice, we haven't declared the variable addition.
07:47 Once again, to print the value of the variable addition, type:
07:53 print double quote Addition is dollar addition slash n close double quote semicolon.
08:05 Save this file
08:07 To compile this file, again on terminal type:
08:12 perl hyphen c multivar dot pl
08:18 There is no syntax error, so we can execute the script
08:24 by typing perl multivar dot pl
08:30 This will produce an output as highlighted.
08:34 Similarly, try subtraction, multiplication and division.
08:38 I have written the code here.
08:41 Now let us save this file and close it.
08:46 Now compile the file by typing
08:48 perl hyphen c multivar dot pl
08:54 There is no syntax error.
08:55 So, we can execute the script as perl multivar dot pl
09:01 On execution the output will look like this.
09:06 This brings us to the end of this tutorial.
09:11 In this tutorial, we have learnt
09:14 to declare and use scalar variables in Perl.
09:18 Assignment:
09:20 Declare a number variable.
09:22 Assign 10 to it.
09:24 Print the variable declared.
09:26 Declare 2 string variables.
09:29 Assign these values to them - “Namaste ” and “India”.
09:34 Print those two variables one after the other.
09:38 Watch the video available at the following link.
09:42 It summarizes the Spoken Tutorial project.
09:45 If you do not have good bandwidth, you can download and watch it.
09:50 The Spoken Tutorial Project Team:
09:53 Conducts workshops using spoken tutorials.
09:56 Gives certificates to those who pass an online test.
10:01 For more details, please write to contact at spoken tutorial dot org.
10:08 Spoken Tutorial Project is a part of the Talk to a Teacher project.
10:13 It is supported by the National Mission on Education through ICT, MHRD, Government of India.
10:23 More information on this mission is available at the following link.
10:29 Hope you enjoyed this Perl tutorial. This is Amol Brahmankar, signing off.
10:34 Thanks for joining.

Contributors and Content Editors

Gaurav, Madhurig, PoojaMoolya, Sandhya.np14, Sneha