PERL/C3/Including-files-or-modules/Gujarati

From Script | Spoken-Tutorial
Revision as of 11:35, 3 February 2016 by Jyotisolanki (Talk | contribs)

Jump to: navigation, search
Time Narration
00:01 PERL પ્રોગ્રામમાં Including files or modules પરના સ્પોકન ટ્યુટોરીયલમાં તમારુ સ્વાગત છે.
00:08 આ ટ્યુટોરીયલમાં આપણે આપેલ મેથડનો ઉપયોગ કરતા શીખીશું
  • do
  • use અને
  • require


00:16 અહી આપણે વાપરી રહ્યા છીએ.
  • Ubuntu Linux 12.04 ઓપરેટીંગ સીસ્ટમ
  • Perl 5.14.2 અને
  • gedit ટેક્સ્ટ એડિટર
00:28 તમે તમારી પસંદગી અનુસાર કોઈ પણ ટેક્સ્ટ એડિટર વાપરી શકો છો.
00:32 આ ટ્યુટોરીયલનાં અનુસરણ માટે તમને Perl પ્રોગ્રામિંગ ની સામાન્ય જાણકરી હોવી જોઈએ.
00:37 જો નથી, તો સંબંધિત ટ્યુટોરીયલો માટે, અમારી વેબસાઇટની મુલાકાત લો.
00:44 'do()' method: આ વર્તમાન સ્ક્રીપ્ટ ફાઈલમાં અન્ય ફાઈલથી સોર્સ કોડ ને સમાવેશ કરવા માટે નો સરળ માર્ગ છે.
00:53 ચાલો do() method ને કેવી રીતે વાપરવું તે વિશે શીખીએ.
00:57 તમારા ટેક્સ્ટમાં નવી ફાઈલ ખોલો અને તેને datetime dot pl નામ આપો.
01:03 datetime dot pl ફાઈલમાં , સ્ક્રીન પર પ્રદશિત ની જેમ આપેલ કોડ ટાઇપ કરો.
01:09 અહી થી આગળ ટર્મિનલ પર દરેક કમાંડ પછીથી એન્ટર કી દબાવવાનું યાદ રાખો.
01:15 ચાલો હવે કોડ સમઝીએ.
01:18 વર્તમાન ડેટ અને ટાઈમ dollar datestring. વેરીએબલમાં સંગ્રહિત કરવામાં આવશે.
01:23 અહી મારી પાસે "msgThanks" નામક એક ફંકશન છે જે એક '“Thank you”' મેસેજ રીટર્ન કરે છે.
01:31 ફાઈલ ને સેવ કરવા માટે Ctrl+S દબાવો.
01:35 આગળ એક અન્ય પર્લ પ્રોગ્રામ જોઈએ જે આ ફાઈલ datetime dot pl. નો ઉપયોગ કરશે.
01:43 તમારા ટેક્સ્ટ એડિટર ઓર એક નવી ફાઈલ ખોલો અને તેને main dot pl નામ આપો.
01:49 main dot pl ફાઈલમાં , સ્ક્રીન પર પ્રદશિત ની જેમ આપેલ કોડ ટાઈપ કરો.
01:55 ચાલો હવે હું કોડ સમઝાવું.
01:58 અહી પ્રથમ લાઈન welcome મેસેજ પ્રિન્ટ કરે છે.
02:03 'do()' method તે ફાઈલના નામ સાથે કોલ થાય છે જ્યાં થી આપણે કોડ ઉપયોગ કરવા ઈચ્છીએ છીએ.
02:09 વર્તમાન ડેટ અને ટાઈમ datetime dot pl file. ના $datestring વેરીએબલમાં સંગ્રહિત થાય છે.
02:16 અને અંતમાં આપણે msgThanks() ફંકશન ને તેજ ફાઈલ થી કોલ કરીએ છીએ.
02:21 હવે ફાઈલને સેવ કરવા માટે Ctrl+S દબાવો.
02:25 ચાલો પ્રોગ્રામ execute કરીએ.
02:27 ટર્મિનલ પર પાછા જાવ અને ટાઈપ કરો perl main dot pl અને એન્ટર દબાવો.
02:34 ટર્મિનલ પર આઉટપુટ નું અવલોકન કરો.
02:37 આગળ આપણે શીખીશું require() method' અને use() method નો પર્લ માં કેવી રીતે ઉપયોગ કરવો.
02:44 આ મેથડસ ત્યારે ઉપયોગ થાય છે જયારે આપણી પાસે subroutines નું સંગ્રહ થાય છે જે મલ્ટીપલ પર્લ પ્રોગ્રામમાં ઉપયોગ કરવામાં આવી શકે છે.
02:52 use() method ફક્ત modules માટે ઉપયોગ કરવા માં આવે છે.
02:56 compilation ના સમયે ચકાશે છે.
02:59 ફાઈલ extension આપવા ની કોઈ જરૂરિયાત નથી.
03:03 require() method પર્લ પ્રોગ્રામસ અને મોડ્યુલસ બંને માટે ઉપયોગ કરાવાય છે.
03:08 It is verified at the run time.
03:10 ફાઈલ એક્સ્ટેંશન આપવાની જરૂરિયાત છે.
03:14 Tuse() method નું સિન્ટેક્સ છે : use module name semicolon.
03:20 Perl modules તે ફાઈલસ હોય છે જે .pm' extension. થી સમાપ્ત થાય છે.
03:25
કોડનો  ફરી ઉપયોગ  modules થી અમલીકરણ થાય છે.
03:30 અન્ય ભાષાઓમાં આ libraries ના સમાન હોય છે.
03:35 હવે હું પર્લ કોડમાં મોડ્યુલને સમાવેશ સમાવેશ કરવા માટે use methodના સાથે સરળ પ્રોગ્રામને દેખાડીશ.
03:43 તમારા ટેક્સ્ટ એડિટર પર એક નવી ફાઈલ ખોલો અને તેને sum dot pm. નામ આપો.
03:49 sum dot pm ફાઈલમાં , સ્ક્રીન પર પ્રદશિત ની જેમ આપેલ કોડ ટાઈપ કરો.
03:55 Here, I have a simple function which will calculate the sum of a given set of numbers. ...............यहाँ, मेरे पास एक सरल प्रोग्राम है जो दिए गए नंबर्स के सेट के जोड़ की गणना करेगा। અહી મારી પાસે એક સરળ પ્રોગ્રામ છે જે આપેલ નંબરસ ના સેટની ગણતરી કરશે.
04:01 હવે ફાઈલને સેવ કરવા માટે Ctrl+S દબાવો.
04:05 આપણે એક અન્ય પર્લ સ્ક્રીપ્ટ લખીશું જ્યાં આપણે આ sum dot pm ફાઈલ ઉપયોગ કરીશું.
04:11 Let me open the sample program app dot pl file which I have saved already.
04:17 In the app dot pl file, type the following code as displayed on the screen.
04:22 Let me explain the code now.
04:25 The first line shows the use method with the module name.
04:29 In our case, the module name is 'sum'.
04:33 We are passing 1, 7, 5, 4,9 as input parameters to the function total() in sum dot pm file.
04:44 Again, in the next line, we are passing 1 to 10 as input parameters to the same function.
04:52 Now, press Ctrl+S to save the file.
04:56 Let us execute the program.
04:59 Switch back to the terminal and type: perl app dot pl and press Enter.
05:06 Observe the output displayed on the terminal.
05:10 Let us see few more options in use method. Switch back to sum dot pm in the text editor.
05:18 At the beginning of the source code, add the lines "use strict" semicolon, "use warnings" semicolon.
05:27 "use strict" and "use warnings" are compiler flags that instruct Perl to behave in a stricter way.
05:35 These are used to avoid common programming mistakes.
05:39 use strict forces the user to declare all the variables used in the program.
05:45 If there are errors, use strict will abort the execution.
05:50 use warnings will only provide warnings but continue with the execution.
05:56 Assume that we forgot to declare the variable $sum as my.
06:02 Let us now see how the same program is executed.
06:06 Press Ctrl+S to save the file.
06:09 Switch back to the terminal and type: perl app dot pl.
06:15 We can see that the program is aborted without executing the result.
06:21 The first set of lines displayed on the terminal are error messages generated by “use strict”.
06:29 The last two are the abort messages.
06:32 So, this is how the use method options work.
06:36 Next, let us see a Perl program where we use the require method.
06:41 Let me open the sample program commonfunctions dot pl which I have already saved.
06:48 Type the following code as displayed on the screen in your commonfunctions dot pl file.

Let us understand the code now.

06:57 Here, we can see a collection of commonly used functions.
07:01 The first function square(), returns the square of a number.
07:06 The second function, square underscore root(), returns the square root of a given number.
07:12 Next function random underscore number(), generates a random number.
07:18 The last function random underscore range(), generates a random number between a lower range and upper range of numbers.
07:26 Note that we need the 1 semicolon at the end of the file.
07:31 This is because Perl needs the last expression in the file to return a true value.
07:37 Now, press Ctrl+S to save the file.
07:41 Next, we will write a Perl program in which we’ll call these subroutines using require method.
07:48 Let me open the sample program callprogram dot pl which I have already saved.
07:54 Type the following code as displayed on the screen in your file. Let me explain the code now.
08:02 require reads the commonfunctions dot pl file containing Perl code and compiles it.
08:09 This program gives 4 options to the user. The user has to choose one option at a time.
08:17 1: (one) is to find the square of a number.
08:20 2: Two is for square root of a number.
08:23 3: Three is for a random number in the given range. 4: Four is to quit the program.
08:29 If option 1 (one) is typed, it will ask the user to enter a number.
08:34 The value is stored in $number. The value is passed to the function square() in commonfunctions dot pl file.
08:44 The function returns the square of a number.
08:47 The print statement prints the square of a number as output.
08:52 If option 2 (two) is typed, the square root of a number is displayed as output.
08:58 The execution is followed as explained in the previous function square().
09:03 If option 3 (three) is typed, a random number is displayed as output in the given range.
09:09 Else, if option is 4 (four), the program exits. If any option other than the ones specified is given, the print statement says “Incorrect option”.
09:20 Note that in this program, we have called only three functions out of four from commonfunctions dot pl.
09:28 Now, press Ctrl+S to save the file.
09:31 Let us execute the program.
09:34 Switch back to the terminal and type: perl callprogram dot pl.
09:41 Observe the output.
09:44 I'll execute the program once again with a different option.
09:49 Type: perl callprogram dot pl.
09:53 Now, enter the option as 3.
09:56 Enter a lower range as 50.
09:59 Enter a upper range as 99.
10:02 We can see the random number is generated in the given range of numbers.
10:08 Try other options on your own.
10:11 This brings us to the end of this tutorial. Let us summarize.
10:16 In this tutorial, we learnt to use:
  • do
  • use
  • require methods in PERL programming.
10:24 Note: "use" module is recommended over "require" module, because it determines module availability at compile time.
10:33 Here is an assignment for you. Write a Perl program reminder.pl where you will write a letter to the participants.
10:41 Prompt the user to enter To and From name.
10:45 Call the subroutines from Letter dot pm using ‘use’ method.
10:50 Write the below functions in Letter dot pm file.
10:54 LetterDate() function returns the current date and time.
10:58 To() function returns the name of the participants.
11:02 From() function returns the sender's name.
11:05 Lettermsg() function returns the contents of the letter.
11:09 Thanksmsg() function returns "thanks" and "regards".
11:13 The output should be displayed as shown here.
11:20 The video at the following link summarizes the spoken tutotial project. Please download and watch it.
11:27 The Spoken Tutorial Project team:
  • conducts workshops using spoken tutorials and
  • gives certificates on passing online tests.
11:36 For more details, please write to us.
11:40 Spoken Tutorial project is funded by NMEICT, MHRD, Government of India.

More information on this mission is available at this link.

11:51 This is Nirmala Venkat from IIT Bombay, signing off. Thanks for watching.

Contributors and Content Editors

Jyotisolanki, PoojaMoolya