PERL/C3/Sample-PERL-program/Gujarati

From Script | Spoken-Tutorial
Revision as of 16:47, 4 February 2016 by Jyotisolanki (Talk | contribs)

Jump to: navigation, search
Time
Narration
00:01 Sample PERL program. ના સ્પોકન ટ્યુટોરીયલમાં તમારુ સ્વાગત છે.
00:06 આ ટ્યુટોરીયલમાં આપણે હમણા સુધી કવર કરેલ મુખ્ય વિષયોને સેમ્પલ પર્લ પ્રોગ્રામમાં સમાવેશ કરવાનું શીખીશું.
00:14 આ ટ્યુટોરીયલ રિકોર્ડ કરવા માટે હું ઉપયોગ કરી રહી છુ.
  • Ubuntu Linux 12.04 ઓપરેટીંગ સીસ્ટમ
  • Perl 5.14.2 અને
  • gedit ટેક્સ્ટ એડિટર.
00:25 તમે તમારી પસંદગી અનુસાર કોઈ પણ ટેક્સ્ટ એડિટર વાપરી શકો છો.
00:29 આ ટ્યુટોરીયલનાં અનુસરણ માટે તમને Perl પ્રોગ્રામિંગ ની સામાન્ય જાણકરી હોવી જોઈએ.
00:34 જો નથી, તો સંબંધિત ટ્યુટોરીયલો માટે, અમારી વેબસાઇટની મુલાકાત લો.
00:39 સેમ્પલ પર્લ પ્રોગ્રામ એક પ્રદેશ નું વિવિધ હવામાનના પૂર્વધારણા રીપોર્ટનું આઉટપુટ આપશે.
00:46 Weather dot pm એક મોડ્યુલ ફાઈલ છે જે આ પ્રોગ્રામના માટે એક જરૂરી ડેટા ને રાખવા માટે એક કોમ્પ્લેક્સ ડેટા સ્ટ્રક્ચર રાખે છે.
00:54 આ રીપોર્ટ બનાવવા માટે અનેક ફંકશન પણ રાખે છે.
00:59 Weather underscore report dot pl એ તે પર્લ પ્રોગ્રામ છે જે જરૂરી જરૂરી આઉટપુટ જોવા માટે આ મોડ્યુલનો ઉપયોગ કરે છે.
01:08 આપણી વેબ સાઈટ પર આ વિડીઓમાં તેજ કોડ ફાઈલ ઉપલબ્ધ છે.
01:13 કોડ ફાઈલ લીંકમાં આપેલ ફાઈલસ ને ડાઉનલોડ અને અનઝિપ કરો.
01:18 હવે આપણું પર્લ પ્રોગ્રામ Weather dot pm. જોઈએ.
01:24 આ પ્રોગ્રામમાં કોડ નું બ્લોક namespace Weather. માં છે.
01:29 પર્લ પેકેજ કીવર્ડ ઉપયોગ કરીને namespace અમલીકરણ કરે છે.
01:34 BEGIN બ્લોક main પ્રોગ્રામ થી પહેલા કમ્પાઈલ અને એક્ઝીક્યુટ કરાવાય છે.
01:40 Export યુઝરના namespace પર મોડ્યુલસ ના વેરીએબલ અને ફંકશન ને એક્સપોર્ટ કરવાની પરવાનગી આપે છે.
01:48 At the rate EXPORT અને at the rate EXPORT underscore OK એક્સપોર્ટ ઓપરેશન ના દરમિયાન ઉપયોગ થયેલ બે મેઈન વેરીએબલસ છે
01:57 At the rate EXPORT સબરૂટીન ની યાદી અને મોડ્યુલ ના વેરીએબલસ ધરાવે છે.


02:03 આ કોલર namespace. માં એક્સપોર્ટ કરાવશે.
02:07 At the rate EXPORT underscore OK જરૂરિયાત અનુસાર સિમ્બોલને એક્સપોર્ટ કરે છે.
02:14 અહી હવામાનના રીપોર્ટ માટે જરૂરી ડેટા રાખવા માટે કોપ્લેક્સ ડેટા- સ્ટ્રક્ચર બનાવવા માટે મેં references ઉપયોગ કર્યું છે.
02:24 $weather_report is a hash reference. “place” and “nstate” have the scalar values.
02:32 weekly” is hash of hash references.
02:37 *Each week day has four keys -
 max underscore temp, 
 min underscore temp, 
 sunrise,
 sunset.
02:48 record underscore time” is an array reference with two index values.
02:54 I have a few subroutines to display the weather report of various options.

Let us see one by one.

03:01 This function prints the header information such as header of the report, place, state and current date.
03:10 Now, let us see the next function display underscore daily underscore report.
03:16 This function prints the daily report on the screen, depending upon the weekday input.
03:22 We retrieve the parameter passed into a subroutine using the shift function.
03:27 I have used the trim() function to remove the leading and trailing spaces of the parameter value.
03:34 Here is the code for the trim() function.
03:37 Lc() function returns a lowercase version of the given input.
03:42 This is used to avoid case-sensitivity.
03:45 The 'week day'- passed as parameter from the main program, is assigned to a local variable dollar week underscore day.
03:55 The following print statements will print the data corresponding to a specified week day.
04:01 We are using the arrow operator to dereference a value in $weather underscore report.
04:09 When working with references, we have to understand the data type we are dereferencing.
04:15 If it is a hash, we need to pass the key in curly braces.
04:20 If it is an array, we need to use the square brackets with the index values.
04:26 return function of Perl returns a value.
04:29 This can be used to check the status of the function in the main program.
04:36 The next function is write underscore daily underscore report.
04:40 This function will print the report output to a file.
04:45 The open function with the greater than (>) symbol defines the WRITE mode.
04:50 Filename is created with the weekday name and dot txt extension.
04:56 The print statements will print the corresponding data of a specified week day to a file.
05:02 This prints the weekly report.
05:05 I have declared a foreach loop to loop through each weekday of the hash reference.
05:11 I have used curly brackets to represent the hash reference and the arrow operator to dereference.
05:18 I am using the “keys” in-built function to loop through the keys of the hash.
05:23 display underscore daily underscore report function will print each element of the hash.
05:30 Now, let us see - a Perl program weather underscore report dot pl where we will make use of this module file Weather dot pm.
05:40 Here, use strict and use warnings are compiler flags that help to avoid common programming mistakes.
05:48 use Weather semicolon. Here, Weather is a module name which I have used in this program.
05:56 We have already seen that the functions required for this program have been stored in this module.
06:03 It is not required to give the dot pm file extension here.
06:08 In this program, I'll print different reports depending upon the given options.
06:14 The user has to enter an option to print the daily weather report of a particular week day,

daily weather report of a particular week day to an output file, weekly weather report.

06:27 If option '1' is typed, it will ask the user to enter the day of a week.
06:32 The diamond operator will read from STDIN, that is, from the keyboard.
06:38 For example, if the user enters 'monday', then it is assigned to a variable dollar dayoption, which is a local variable.
06:47 Next, we can see that we are calling two functions-
  • display_header() and
  • display_daily_report().
06:56 We have exported all functions in Weather dot pm with “use Weather” statement in this file.
07:03 So, no need to refer the functions within a package using the colon colon (::)package qualifier
07:10 Now let's see the next option.
07:13 If option '2' is typed, it will prompt the user to enter the day of a week.
07:19 $dayoption is passed as the input parameter to the function write underscore daily underscore report.
07:27 return value from the function is stored in the variable dollar result.
07:33 Print statement asks the user to check the text file for the output.
07:38 The filename is created with the day of the week dot txt as output file.
07:46 If option '3' is typed, it prints the weather report for the whole week.
07:51 display underscore weekly underscore report is the function name of the weekly report.
07:57 This print statement draws a horizontal line for the specified number of times.
08:02 This is just to give a good look to the report.
08:06 Lastly, if the option is 4, it will quit the program.
08:11 If any option other than the ones specified is given, the print statement says “Incorrect option”.
08:19 Here, the exit value of '0' indicates the program ran successfully.
08:25 The exit value other than '0' means an error of some kind has occurred.
08:31 Now, let us execute the program.
08:34 Switch to the terminal and type perl weather underscore report dot pl and press Enter.
08:41 We can see four options on the screen.
08:45 Type '1 'and press Enter.
08:48 We are prompted to enter a day of the week. I'll type "monday" and press Enter.
08:56 This is the header output generated from the function display underscore header().
09:02 Now, we can see the weather report of Monday.
09:06 Now I'll again execute the program once again to demonstrate the other options.
09:13 Type 2 and press Enter.
09:17 At the prompt, we have to type any week day. I will type "wednesday" and press Enter.
09:25 We can see a message: Please check the file wednesday dot txt for report output .
09:32 The output has been written to this text file. Let us open the file and check the contents.
09:38 Type: gedit wednesday dot txt and press Enter.
09:44 The output file has been created with the entered week day name with 'txt' extension.
09:51 Now, let us check the next option.
09:54 Switch to the terminal and type: perl weather underscore report dot pl and press Enter.
10:00 Type '3 'and press Enter.
10:04 This time, we can see the weekly weather report.
10:08 The hash keys and hash values are stored in a random order.
10:13 So, the displayed output is not related to the order in which they were added.
10:19 With this, we come to the end of this tutorial. Let us summarize.
10:24 In this tutorial, we have seen a sample Perl program by covering main topics of our previous tutorials.
10:32 As an assignment, write a similar Perl program employee underscore report.pl for displaying employee salary, designation, department, leave_balance details.
10:45 Pass Employee ID or Employee name as input.
10:50 Write the required functions in the module Employee dot pm file.
10:56 The video at the following link summarize the spoken tutorial. Please download and watch it.
11:03 We conduct workshops and give certificates for those who pass our online tests.

For more details, please write to us.

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

More information on this mission is available at this link.

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

Contributors and Content Editors

Jyotisolanki, PoojaMoolya