PERL/C2/Functions-in-Perl/Gujarati
From Script | Spoken-Tutorial
Revision as of 12:51, 3 February 2015 by Jyotisolanki (Talk | contribs)
| Time | Narration |
| 00:01
પર્લમાં ' Functions પરના ટ્યુટોરીયલમાં તમારું સ્વાગત છે. . | |
| 00:06 | આ ટ્યુટોરીયલમાં આપણે આપેલ વિષે શીખીશું- |
| 00:10 | Perl functions (પર્લ ફન્કશન) |
| 00:11 | arguments 'સાથે functions' |
| 00:13 | return values સાથે functions |
| 00:16 | આ ટ્યુટોરીયલ માટે હું વાપરી રહી છું. |
| 00:18 | ઉબુન્ટુ લીનક્સ 12.04 ઓપરેટીંગ સીસ્ટમ |
| 00:22 | પર્લ 5.14.2 અને |
| 00:24 | gedit ટેક્સ્ટ એડિટર |
| 00:27 | તમે તમારી ઈચ્છા અનુસાર કોઈ પણ ટેક્સ્ટ એડિટર વાપરી શકો છો. |
| 00:31 | પર્લમાં તમને વેરીએબલ, કમેન્ટ્સ,લૂપ્સ,કન્ડીશનલ સ્ટેટમેંટ અને ડેટા સ્ટ્રક્ચર વિષે સામાન્ય જાણકારી હોવી જરૂરી છે. |
| 00:41 | સંદર્ભિત ટ્યુટોરીયલો માટે કૃપા કરી સ્પોકન ટ્યુટોરીયલ વેબસાઈટનો સંદર્ભ લો. |
| 00:47 | આપણે પહેલા અમુક સમાન્ય પર્લ ફંક્શન વિષે જોશું. |
| 00:51 | પર્લમાં ફંક્શન ને subroutines, પણ કહેવાય છે જે sub keyword. સાથે ડીકલેર કરવા માં આવે છે. |
| 00:57 | ડીકલેર ફંક્શનની વ્યાખ્યા સર્પાકાર કૌંસ માં લખવા માં આવે છે. |
| 01:03 | આ ફંક્શન કોઈ પણ આર્ગ્યુંમેંટ નથી લેતી. |
| 01:07 | અને આ કઈ પણ પાછુ નથી આપતી. |
| 01:10 | નોંધ: ફંક્શન ની વ્યાખ્યા સ્ક્રીપ્ટમાં કોઈ પણ સ્થાને અથવા કોઈ અન્ય મોડ્યુલમાં લખી શકાય છે. |
| 01:17 | આ મોડ્યુલ પછી આ ફંક્શનનો ઉપયોગ કરીને સ્ક્રીપ્ટમાં સમાવેશ કરવામાં આવે છે. |
| 01:24 | મોડ્યુલ ફાઈલને સ્ક્રીપ્ટમાં સમાવેશ કરવા માટે આપેલ સિન્ટેક્સ નો ઉપયોગ કરવો પડે છે- |
| 01:31 | use ModuleFileName semicolon |
| 01:35 | સેમ્પલ પ્રોગ્રામ નો ઉપયોગ કરીને ચાલો આને સમજીએ. |
| 01:39 | તમારા ટેક્સ્ટ એડિટરને ખોલો અને tene simpleFunction dot pl તરીકે નામ આપો. |
| 01:46 | અહી મારી simpleFunction dot pl ફાઈલ gedit. માં છે. |
| 01:51 | સ્ક્રીન પર બતાડેલ કોડ ટાઈપ કરો. |
| 01:55 | અહી આપણે ફક્ત ફંકશન ને કોલ કરી રહ્યા છે જે આપણે વ્યાખ્યાયિત કર્યું છે. |
| 02:00 | પછી એક્ઝેક્યુશન કંટ્રોલ તે ફંક્શનમાં પાસ થઇ જાય છે. |
| 02:06 | આ ફંક્શનનું ડીકલેરેશન અને વ્યાખ્યા છે. |
| 02:10 | This function will print out the given text. |
| 02:14 | Save your file. |
| 02:17 | Then switch to the terminal and execute the Perl script by typing |
| 02:24 | perl simpleFunction dot pl |
| 02:28 | and press Enter. |
| 02:30 | The output will be as shown on the terminal |
| 02:38 | Now, let us see a function with arguments. |
| 02:44 | Let us understand this function using a sample program. |
| 02:48 | Open a file in your text editor and name it as functionWithArgs dot pl |
| 02:57 | Here is my functionWithArgs script in gedit. |
| 03:02 | Type the following piece of code as shown on the screen. |
| 03:07 | Here, we are calling a function with arguments, 10 and 20. |
| 03:13 | The passed arguments are caught in $var1 & $var2. |
| 03:20 | @_ is a special Perl variable. We will cover its details in future tutorials. |
| 03:29 | This function performs the addition of 2 variables and prints the answer. |
| 03:37 | Save your file. |
| 03:42 | @_ is a special Perl array. |
| 03:46 | This array is used to store the passed arguments. |
| 03:51 | Similarly, we can catch the passed arguments in variables as |
| 03:56 | $var1 space = space shift @_ semicolon |
| 04:04 | $var2 space = space shift @_ semicolon |
| 04:12 | shift @_ removes the element at first position from @_ array |
| 04:21 | and assigns it to a variable |
| 04:24 | Another way is; $var1 space = space dollar underscrore open square bracket zero close square bracket semicolon |
| 04:38 | $var2 space = space dollar underscrore open square bracket 1 close square bracket semicolon |
| 04:49 | The above mentioned way is similar to fetching elements of @_ array using index. |
| 04:59 | Now, switch to terminal and execute the script by typing - |
| 05:06 | perl functionWithArgs dot pl and press Enter |
| 05:14 | The output is as displayed on the screen |
| 05:23 | Now, let us look at a functions which returns a single value. |
| 05:32 | Let us understand the same using a sample program. |
| 05:35 | Let me switch to funcWithSingleRtrnVal dot pl script in gedit. |
| 05:46 | Open a file in your text editor and type the following piece of code as shown. |
| 05:52 | Here, we are calling addVariables function with parameters 10 and 20. |
| 06:01 | The return value of the function is caught in $addition variable. |
| 06:09 | This function does the addition of the passed parameters and returns the answer. |
| 06:15 | Save the file. |
| 06:17 | Now let us execute the script. |
| 06:20 | So, switch to terminal and type- |
| 06:24 | perl funcWithSingleRtrnVal dot pl and press Enter. |
| 06:35 | The output is as displayed on the terminal. |
| 06:43 | Now, let us see a function which returns multiple values. |
| 06:48 | Let us understand the same, using a sample program. |
| 06:53 | In gedit, I have opened a file and named it as funcWithMultipleRtrnVals dot pl |
| 07:04 | Please do like wise in your text editor |
| 07:08 | Now, type the following piece of code as shown. |
| 07:13 | Here, we are calling addVariables function with parameters 10 and 20. |
| 07:21 | The return values of the function are caught in variables $var1, $var2 and $addition |
| 07:31 | This function does the addition and returns the passed parameters and the resultant answer. |
| 07:42 | This illustration demonstrates how we can return an array from a function. |
| 07:53 | Similarly, this demonstrates how hash can be returned from a function. |
| 08:00 | Save your file. |
| 08:03 | Now let us execute the Perl script on the terminal by typing - |
| 08:10 | perl funcWithMultipleRtrnVals dot pl |
| 08:18 | and press Enter. |
| 08:20 | The output is as displayed on the terminal. |
| 08:32 | Perl provides several inbuilt functions. |
| 08:36 | We learnt some of them in earlier tutorials. For eg- Arrays, Hash, sort, scalar, each, keys etc. |
| 08:49 | Calling inbuilt functions, similar to calling any other function, which we define. |
| 08:57 | E.g sort open bracket @arrayName close bracket semicolon |
| 09:04 | Try incorporating some inbuilt functions in the sample programs we used. |
| 09:10 | And observe their outputs. |
| 09:13 | Let us summarize. |
| 09:15 | In this tutorial, we have learnt - |
| 09:17 | Functions in Perl |
| 09:19 | functions with arguments and |
| 09:22 | functions which return values using sample programs. |
| 09:27 | Here is assignment for you - |
| 09:29 | Write a function which takes 3 arguments. |
| 09:33 | Perform some action on these arguments |
| 09:37 | Return the result of the action performed on the arguments and print the same. |
| 09:43 | Watch the video available at the following link |
| 09:47 | It summaries the Spoken Tutorial project |
| 09:51 | If you do not have good bandwidth, you can download and watch it |
| 09:56 | The Spoken Tutorial Project Team Conducts workshops using spoken tutorials |
| 10:02 | Gives certificates to those who pass an online test |
| 10:07 | For more details, please write to contact at spoken hyphen tutorial dot org |
| 10:14 | Spoken Tutorial Project is a part of the Talk to a Teacher project |
| 10:19 | It is supported by the National Mission on Education through ICT, MHRD, Government of India. |
| 10:28 | More information on this Mission is available at spoken hyphen tutorial dot org slash NMEICT hyphen Intro |
| 10:40 | Hope you enjoyed this Perl tutorial. |
| 10:43 | This is Amol signing off. |
| 10:46 | Thanks for joining. |