Difference between revisions of "PERL/C3/Access-Modifiers-in-PERL/Gujarati"
From Script | Spoken-Tutorial
Jyotisolanki (Talk | contribs) |
Jyotisolanki (Talk | contribs) |
||
Line 98: | Line 98: | ||
|- | |- | ||
|02:17 | |02:17 | ||
− | + | |મારી પાસે પહેલાથી એક સેમ્પલ પ્રોગ્રામ છે. હું આને ''''gedit''' Text editor''' માં ખોલીશ. | |
|- | |- |
Revision as of 16:24, 15 January 2016
|
|
00:01 | Spoken Tutorial on Access Modifiers in PERL પરના આ સ્પોકન ટ્યુટોરીયલમાં સ્વાગત છે. . |
00:07 | આ ટ્યુટોરીયલમાં આપણે આપણે શીખીશું:
|
00:19 | આ ટ્યુટોરીયલ માટે હું ઉપયોગ કરી રહી છું:
|
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 | The last print statement in this program will not print any output. |
03:23 | This is because outside the scope of the blocks defined earlier, fname has no value assigned to it. |
03:32 | Now, press Ctrl+S to save the file. |
03:37 | Let us now execute the program. |
03:40 | Switch back to the terminal and type: perl scope hyphen my dot pl and press Enter. |
03:49 | The output is displayed as:
"Block 1: Raghu" "Block 2: Other" "Outside Block: " there is no output. |
03:59 | So, the scope of the 'my' variable is accessed only within a particular block of code. |
04:06 | Now, let us change the existing program a little. |
04:10 | Let us add my $fname = within double quotes John semicolon outside the blocks, before the last print statement.
Save the changes. |
04:23 | Switch back to the terminal and execute as before. |
04:28 | Analyze the output that is displayed. |
04:32 | Hope you are able to understand the scope of using 'my' variable within a block and outside a block. |
04:41 | Next, we will see about dynamically scoped variable in Perl. |
04:47 | Local keyword gives a temporary scope to a global variable. |
04:52 | The variable is visible to any function called from the original block. |
04:58 | You can declare a local variable as:
local $fValue = 100 semicolon local $fname” = within double quotes Rakesh semicolon |
05:13 | Let us understand this using a sample program. |
05:17 | Open the terminal and type: gedit scope hyphen local dot pl ampersand and press Enter. |
05:27 | This will open scope hyphen local dot pl file in gedit. |
05:33 | Type the following code as displayed on the screen. Let me explain the code now. |
05:40 | Here, in the first line, we have declared a variable $fname and initialized it. |
05:47 | Inside the function Welcome(), we have declared a local variable by the same name, $fname. |
05:54 | Notice the local keyword before the variable name |
05:59 | and we have assigned the value "Rakesh" to this variable. |
06:03 | So, basically, inside function Welcome(), $fname is modified as a new temporary local variable.
Then, the function Hello() is being called. |
06:15 | Here is the function definition of Hello(). |
06:18 | At the end of the program, we are calling both the functions Welcome() and Hello(). |
06:25 | Now press Ctrl + S to save the program. |
06:29 | Let us execute the program. |
06:31 | Switch back to the terminal and type: perl scope hyphen local.pl and press Enter. |
06:41 | The output is displayed as:
"Hello, Rakesh"! "Hello, Welcome to Spoken tutorials!" |
06:48 | Let us understand the output. |
06:51 | When the function Welcome() is called, the function Hello() within it, accesses the local variable. |
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:
|
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. |