Difference between revisions of "PERL/C3/Access-Modifiers-in-PERL/Gujarati"

From Script | Spoken-Tutorial
Jump to: navigation, search
Line 235: Line 235:
 
|-
 
|-
 
| 05:59
 
| 05:59
| and we have assigned the value "Rakesh" to this variable.
+
| અને આપણે આ વેરીએબલને વેલ્યુ  '"Rakesh"' અસાઇન કરી છે.
  
 
|-
 
|-
 
| 06:03
 
| 06:03
| So, basically, inside function '''Welcome(), $fname''' is modified as a new temporary '''local''' variable.
+
|   તો; મૂળભૂત ફંકશન  '''Welcome(),માં  $fname''' એક અસ્થાયી લોકલ વેરીએબલની જેમ સુધારિત થાય છે.
Then, the function '''Hello() '''is being '''call'''ed.
+
Then, the function પછી ફંકશન  '''Hello() ''' કોલ કરવા માં આવે છે.
  
 
|-
 
|-
 
|06:15
 
|06:15
|Here is the function definition of '''Hello()'''.
+
| અહી '''Hello()''' નું ફંકશન ડેફીનેશન છે.
  
 
|-
 
|-
 
|06:18
 
|06:18
|At the end of the program, we are calling both the functions '''Welcome()''' and '''Hello()'''.
+
| પ્રોગ્રામના અંતમાં આપણે બંને ફંકશનસ  '''Welcome()''' અને  '''Hello()''' ને કોલ કરી રહ્યા છીએ.
  
 
|-
 
|-
 
|06:25
 
|06:25
|Now press''' Ctrl + S''' to save the program.
+
| હવે પ્રોગ્રામને સેવ કરવા માટે ''' Ctrl + S''' દબાવો.
  
 
|-
 
|-
 
|06:29
 
|06:29
|Let us execute the program.
+
| ચાલો પ્રોગ્રામને એક્ઝીક્યુટ કરીએ.
  
 
|-
 
|-
 
|06:31
 
|06:31
|Switch back to the '''terminal''' and type: '''perl scope hyphen local.pl''' and press '''Enter'''.
+
|ટર્મિનલ પર જાવ અને ટાઈપ કરો; '''perl scope hyphen local.pl''' અને  '''Enter''' દબાવો.
  
 
|-
 
|-
 
|06:41
 
|06:41
|The output is displayed as:
+
| આઉટપુટ આપેલની જેમ દેખાય છે:
 
"Hello, Rakesh"!
 
"Hello, Rakesh"!
 
"Hello, Welcome to Spoken tutorials!"
 
"Hello, Welcome to Spoken tutorials!"
Line 270: Line 270:
 
|-
 
|-
 
|06:48
 
|06:48
|Let us understand the output.
+
| ચાલો આઉટપુટ ને સમઝીએ.  
  
 
|-
 
|-
 
|06:51
 
|06:51
|When the function '''Welcome()''' is called, the function '''Hello()''' within it, accesses the '''local''' variable.
+
| જયારે ફંકશન  '''Welcome()''' કોલ થાય છે તો તેના અંદર ફંકશન '''Hello()''' '''local''' વેરીબ્લ એક્સેસ કરે છે.
 
+
 
|-
 
|-
 
| 06:59
 
| 06:59

Revision as of 16:34, 18 January 2016

Time
Narration
00:01 Spoken Tutorial on Access Modifiers in PERL પરના આ સ્પોકન ટ્યુટોરીયલમાં સ્વાગત છે.
00:07 આ ટ્યુટોરીયલમાં આપણે આપણે શીખીશું:
  • Scope of variables
  • Private variables
  • Dynamically scoped variables
  • Global variables
00:19 આ ટ્યુટોરીયલ માટે હું ઉપયોગ કરી રહી છું:
  • Ubuntu Linux 12.04 operating system
  • Perl 5.14.2 અને
  • gedit Text Editor.
00:32 તમે તમારી પસંદગી અનુસાર કોઈ પણ ટેક્સ્ટ એડિટર વાપરી શકો છો.
00:36 તમને Perl પ્રોગ્રામિંગ વિષે સામાન્ય જાણકારી હોવી જોઈએ.
00:40 જો નથી તો સ્પોકન ટ્યુટોરિયલ વેબ સાઈટ પર ઉપલબ્ધ Perl ટ્યુટોરિયલ જુઓ.
00:47 ચાલો scope of variables. ના પરિચય સાથે શરૂઆત કરીએ.
00:51 વેરીએબલ નું સ્કોપ કોડ નું એ શેત્ર છે. જેમાં વેરીએબલ ને એક્સેસ કરવામાં આવી શકે છે .
00:58 બીજા શબ્દ માં , આ વેરીએબલસ ની પ્રત્યક્ષતાને દેખાડે છે.
01:03 પ્રથમ આપણે Perl. માં my, local અને our modifiers ના વિષે ચર્ચા કરીશું.
01:10 my એટલેકે Private variables,
01:13 local એટલેકે Dynamically scoped variables,
01:17 our એટલેકે Global variables'.
01:20 વેરીએબલસ જે my કીવર્ડના સાથે ડીકલેર થયા છે બ્લોકના બહાર સ્કોપ સ્કોપ ને ગુમાવી દેશે જેમાં તે ડીકલેર થયા છે.
01:28 તમે આપેલ પ્રકારની વેલ્યુ આપ્યા વગર એક વેરીએબલ ડીકલેર કરી શકો છો.

my $fvalue semicolon

01:37 તમે આને એક વેલ્યુ અસાઇન કરીને એક વેરીએબલ પણ ડીકલેર કરી શકો છો.
01:43 my $fValue = 1 semicolon
01:48 my $fname = ડબલ કોટ માં Rahul semicolon
01:55 તેજ my સ્ટેટમેંટ ના અસ્થે અનેક વેરીએબલસ ને ડીકલેર કરવા માટે સિન્ટેક્સ આપેલ આપેલ પ્રકાર છે.
02:02 my ખુલો કૌંસ $fname comma $lname comma $age બંદ કૌંસ
02:12 હવે એક સેમ્પલ પ્રોગ્રામનો ઉપયોગ કરીને private વેરીએબલસ ને સમઝીએ.
02:17 મારી પાસે પહેલાથી એક સેમ્પલ પ્રોગ્રામ છે. હું આને 'gedit Text editor માં ખોલીશ.
02:24 ટર્મિનલ ખોલો અને ટાઈપ કરો : gedit scope hyphen my dot pl ampersand અને Enter દબાવો.
02:34 Scope-my dot pl ફાઈલ હવે જી એડિટમાં ખુલે છે.
02:39 સ્ક્રીન પર પ્રદશિત આપેલની જેમ કોડ ટાઈપ કરો. ચાલો હું કોડ સમજાવું.
02:46 અહી મેં 'my' કીવર્ડ સાથે એક private વેરીએબલ $fname ને ડીકલેર કર્યું છે.
02:52 અને તેને "Raghu" વેલ્યુ અસાઇન કરી છે.
02:56 આ બ્લોકમાં print સ્ટેટમેંટ fname વેરીએબલ જેકે "Raghu" છે તેમાં વેલ્યુ પ્રિન્ટ કરે છે.
03:04 આગલા બ્લોકમાં હું તેજ private' વેરીએબલ $fname. ને '"Other"' વેલ્યુ અસાઇન કરી છે.
03:11 તો, પ્રિન્ટ સ્ટેટમેંટ આ વિશેષ બોલ્કમાં "Other" પ્રિન્ટ કરશે.
03:17 આ પ્રોગ્રામમાં છેલ્લે પ્રિન્ટ સ્ટેટમેંટ કોઈ આઉટપુટ પ્રિન્ટ નહી કરશે.
03:23 આવું એટલા માટે છે કેમકે પહેલા વ્યાખ્યાયિત બ્લોકસ ના સ્કોપના બહાર fname એ આના પર કોઈ વેલ્યુ અસાઇન નથી કરી.
03:32 હવે ફાઈલને સેવ કરવા માટે Ctrl+S દબાવો.
03:37 ચાલો હવે પ્રોગ્રામને એક્ઝીક્યુટ કરીએ.
03:40 ટર્મિનલ પર પાછા જાવ અને ટાઈપ કરો perl scope hyphen my dot pl અને Enter દબાવો.
03:49 આઉટપુટ આપેલ ની જેમ દેખાય છે:

"Block 1: Raghu"

"Block 2: Other"

"Outside Block: " માં કોઈ પણ આઉટપુટ નથી.

03:59 તો 'my' variable નું સ્કોપ ફક્ત કોડ ના એક વિશેષ બ્લોકમાં એક્સેસ થાય છે.
04:06 હવે વર્તમાન પ્રોગ્રામને થોડું બદલીએ.
04:10 હવે છેલ્લા પ્રિન્ટ સ્ટેટમેંટ પહેલા બ્લોકસના ભાર ઉમેરીએ my $fname = ડબલ કોટસમાં John semicolon
04:23 ટર્મિનલ પર પાછા જાવ અને પહેલાની જેમ એક્ઝીક્યુટ કરો.
04:28 દ્રશ્યમાન આઉટપુટ નું અવલોકન કરો.
04:32 આશા છે તમે 'my' વેરીએબલ ઉપયોગ કરીને બ્લોક માં અને બ્લોકથી બહાર સ્કોપને સમઝવા માટે સક્ષમ છો.
04:41 આગળ આપણે Perl માં dynamically scoped variable ના વિષે જોશું.
04:47 લોકલ કીવર્ડ global વેરીએબલને એક અસ્થાયી સ્કોપ આપે છે.
04:52 તે વેરીએબલ અસલ બ્લોકથી કોલ થયેલ કોઈ પણ ફંકશન પર દ્રશ્યમાન થાય છે.
04:58 તમે આપેલની જેમ local વેરીએબલને ડીકલેર કરી શકો છો:

local $fValue = 100 semicolon

local $fname” = double quotes માં Rakesh semicolon

05:13 હવે એક સેમ્પલ પ્રોગ્રામનો ઉપયોગ કરીને આને સમઝાવીએ.
05:17 ટર્મિનલ ખોલો અને ટાઈપ કરો: gedit scope hyphen local dot pl ampersand અને Enter દબાવો.
05:27 gedit માં scope hyphen local dot pl ફાઈલને ખોલશે.
05:33 સ્ક્રીન પર પ્રદશિતની જેમ કોડ ટાઈપ કરો. ચાલો હું કોડ સમઝાવું.
05:40 અહી પહેલી લાઈન માં આપણે એક વેરીએબલ $fname ને ડીકલેર કર્યું છે અને આને ઈનીશીલાઈઝ કર્યું છે.
05:47 ફંકશન Welcome() માં આપણે તેજ નામ $fname. થી એક local વેરીએબલને ડીકલેર કર્યું છે.
05:54 વેરીએબલના નામના આગળ local કીવર્ડ પર ધ્યાન આપો.
05:59 અને આપણે આ વેરીએબલને વેલ્યુ '"Rakesh"' અસાઇન કરી છે.
06:03 તો; મૂળભૂત ફંકશન Welcome(),માં $fname એક અસ્થાયી લોકલ વેરીએબલની જેમ સુધારિત થાય છે.

Then, the function પછી ફંકશન Hello() કોલ કરવા માં આવે છે.

06:15 અહી Hello() નું ફંકશન ડેફીનેશન છે.
06:18 પ્રોગ્રામના અંતમાં આપણે બંને ફંકશનસ Welcome() અને Hello() ને કોલ કરી રહ્યા છીએ.
06:25 હવે પ્રોગ્રામને સેવ કરવા માટે Ctrl + S દબાવો.
06:29 ચાલો પ્રોગ્રામને એક્ઝીક્યુટ કરીએ.
06:31 ટર્મિનલ પર જાવ અને ટાઈપ કરો; perl scope hyphen local.pl અને Enter દબાવો.
06:41 આઉટપુટ આપેલની જેમ દેખાય છે:

"Hello, Rakesh"! "Hello, Welcome to Spoken tutorials!"

06:48 ચાલો આઉટપુટ ને સમઝીએ.
06:51 જયારે ફંકશન Welcome() કોલ થાય છે તો તેના અંદર ફંકશન Hello() local વેરીબ્લ એક્સેસ કરે છે.
06:59 Within Welcome(), $fname has the value "Rakesh".
07:04 After this, the function Hello() accesses the variable $fname once again.
07:11 But this time, it is the variable $fname which was initialized to "Welcome to spoken tutorials".
07:19 It does not access the local variable $fname within the function Welcome().
07:25 Which means that, the local variable restores the scope, after leaving the block Welcome().
07:32 Next, we will see about global variables in Perl.
07:38 A global variable can be accessed anywhere in the program.
07:43 Global variables are declared with 'our' keyword.
07:47 Here are some examples.

our $fvalue = 100 semicolon </nowiki> our $fname =within double quotes Priya semicolon

08:01 Now, let us look at a working example of global variables.
08:06 Switch back to the terminal and type: gedit scope hyphen our dot pl ampersand and press Enter.
08:16 This will open the file scope hyphen our.pl in gedit.
08:22 Let me explain the sample program which I have written.
08:27 I have declared package main and a global variable as our $i and I have initialized it to 100.
08:37 Notice the package First declaration.
08:40 A package is a collection of code which has its own namespace.
08:46 Namespace prevents variable name collisions between packages.
08:51 We will see more about package and namespace in future tutorials.
08:56 Within package First, the global variable "i" holds the value 10.
09:02 In package Second, the global variable "i" is assigned the value 20.
09:08 The main package uses both package First variable and the package Second variable.
09:15 In my program, I have declared the same variable "i" in all the packages.
09:21 The package variable is referred by package name colon colon variable name.
09:29 In our example, it is $First colon colon i, $Second colon colon i.
09:39 We have multiple packages within one file and the global variable will be accessed by all the packages.
09:47 Now, save the file and execute the program.
09:51 So, switch to terminal and type: perl scope hyphen our dot pl and press Enter.
09:59 The output is as displayed on the terminal.
10:03 Analyze the output by yourself to understand how the assignment to the variable i was done.
10:11 This brings us to the end of this tutorial. Let us summarize.
10:16 In this tutorial, we learnt:
  • scope of variables
  • declaration of private variables
  • dynamically scoped variables and
  • global variables with examples.
10:29 It is preferred to use 'my' than local, as the compilation is faster.
10:35 Here is an assignment for you.
10:37 Write the code for the following assignment and execute it.
10:42 Declare a package as FirstModule.
10:46 Declare a variable $age as our and assign the value 42.
10:52 Declare another package as SecondModule.
10:56 Declare a variable $ageword as our and assign the value within double quotes "Forty-Two".
11:05 Declare a subroutine First().
11:08 Inside the subroutine, declare two variables with local and my keyword as below:
11:16 local $age = 52 semicolon
11:20 my $ageword = within double quotes Fifty-two semicolon
11:27 Call another subroutine as Result().
11:31 Print the values of $age and $ageword inside this function.
11:37 End the subroutine.
11:39 Declare the subroutine Result().
11:42 Again print the values of $age and $ageword.
11:47 End the subroutine.
11:49 Call the function First().
11:51 Print the Package First and Package Second as below:
11:57 The video at the following link summarizes the Spoken Tutorial project.

Please download and watch it.

12:05 The Spoken Tutorial project team conducts workshops and gives certificates for those who pass an online test.

For more details, please write to us.

12:18 Spoken Tutorial project is funded by NMEICT, MHRD, Government of India.

More information on this mission is available at this link.

12:31 This is Nirmala Venkat from IIT Bombay, signing off. Thanks for watching.

Contributors and Content Editors

Jyotisolanki, PoojaMoolya