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

From Script | Spoken-Tutorial
Revision as of 12:27, 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 અહી મારી પાસે એક સરળ પ્રોગ્રામ છે જે આપેલ નંબરસ ના સેટની ગણતરી કરશે.
04:01 હવે ફાઈલને સેવ કરવા માટે Ctrl+S દબાવો.
04:05 આપણે એક અન્ય પર્લ સ્ક્રીપ્ટ લખીશું જ્યાં આપણે આ sum dot pm ફાઈલ ઉપયોગ કરીશું.
04:11 હવે હું સેમ્પલ પ્રોગ્રામ app dot pl ફાઈલને મેં ખોલીશ જે મેં પહેલાથી જ સેવ કરેલ છે.
04:17 app dot pl ફાઈલમાં સ્ક્રીન પર પ્રદશિતની જેમ આપેલ કોડ ટાઈપ કરો.
04:22 ચાલો હવે કોડ સમઝાવું.
04:25 પ્રથમ લીન મોડ્યુલ નામના સાથે use method દેખાડે છે.
04:29 આપણા કિસ્સા માં મોડ્યુલ નામ sum છે.
04:33 આપણે sum dot pm ફાઈલમાં total() ફંકશન પર ઈનપુટ પેરામીટરસ 1, 7, 5, 4,9 as પાસ કરી રહ્યા છીએ.
04:44 ફરી આગલી લાઈનમાં આપણે તેજ ફંકશન પર 1 થી 10 સુધી ઈનપુટ પેરામીટરસ પાસ કરી રહ્યા છીએ.
04:52 ફાઈલ ને સેવ કરવા માટે Ctrl+S દબાવો.
04:56 ચાલો પ્રોગ્રામ execute કરીએ.
04:59 ટર્મિનલ પર જાવ અને ટાઈપ કરો : perl app dot pl અને એન્ટર દબાવો.
05:06 ટર્મિનલ પર પ્રદશિત આઉટપુટ નું અવલોકન કરો.
05:10 હવે use method માં અમુક વધી વિકલ્પો જોઈએ. ટેક્સ્ટ એડિટરમાં sum dot pm પર પાછા જાવ.
05:18 સોર્સ કોડની શરૂઆત માં આપેલ લાઈનસ ઉમેરો '" use strict" semicolon, "use warnings" semicolon.
05:27 compiler flags છે જે પર્લ ને સખતીથી વ્યવહાર કરવા માટે નિર્દેશ આપે છે.
05:35 સામન્ય પ્રોગ્રામિંગ ની ભૂલોને રોકવા માટે ઉપયોગ થાય છે.
05:39 use strict પ્રોગ્રામમાં ઉપયોગ થયેલ બધા વેરીએબલસ ને ડીકલેર કરવા માટે યુજરસ ન આગ્રહ કરે છે.
05:45 જો એરરસ હોય છે તો use strict એક્ઝીક્યુશન ને બંધ કરો.
05:50 use warnings ફક્ત વોર્નિગ આપશે પણ એક્ઝીક્યુશન ચાલુ રાખશે.
05:56 ધારો કે my ની જેમ વેરીએબલ $sum ડીકલેર કરવાનું ભૂલી ગયા.
06:02 હવે જોઈએ કે સમાન પ્રોગ્રામ ને એક્ઝીક્યુટ કેવી રીતે કરે છે
06:06 ફાઈલ ને સેવ કરવા માટે Ctrl+S દબાવો.
06:09 ટર્મિનલ પર પાછા જાવ અને ટાઈપ કરોperl app dot pl.
06:15 આપણે જોઈ શકીએ છીએ કે પરિણામના એક્ઝીક્યુશન વગર જ પ્રોગ્રામ બંદ થાય છે.
06:21 ટર્મિનલ પર પ્રદશિત લાઈનો નું પ્રથમ સેટ “use strict” દ્વારા ઉત્પન્ન error messages છે.
06:29 છેલ્લા બે abort છે.
06:32 તો: આ પ્રકારે use method વિકલ્પ કાર્ય કરે છે.


06:36 આગળ હવે આપણે એક પર્લ પ્રોગ્રામ જોઈએ જ્યાં આપણે require મેથડનો ઉપયોગ કરીએ છીએ.
06:41 હવે આપણે એક સેમ્પલ પ્રોગ્રામ commonfunctions dot pl ખોલીશું જે એક પહેલાથી જ સેવ કરેલ હતી.
06:48 તમારા commonfunctions dot pl ફાઈલમાં સ્ક્રીન પર પ્રદશિતની જેમ આપેલ કોડ ટાઈપ કરો.
06:57 અહી આપણે સામાન્ય રીતે ઉપયોગ થયેલ ફંકશન નું સંગ્રહ જોઈ શકીએ છીએ.
07:01 પ્રથમ ફંકશન square(), નંબર નું વર્ગ રીટર્ન કરે છે.
07:06 બીજો ફંકશન square underscore root() આપેલ નંબરનું વર્ગમૂળ રીટર્ન કરે છે.
07:12 આગલું ફંકશન random underscore number(), એક રેન્ડમ નંબર ઉત્પન કરે છે.
07:18 છેલ્લું ફંકશન random underscore range(), નંબરસ ના અપર રેંજ અને લોવર રેંજ ના વચ્ચે એક રેન્ડમ નંબર ઉત્પન કરે છે.
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