Difference between revisions of "PERL/C2/Hash-in-Perl/Gujarati"
From Script | Spoken-Tutorial
Jyotisolanki (Talk | contribs) |
Jyotisolanki (Talk | contribs) |
||
| Line 109: | Line 109: | ||
|- | |- | ||
|01:53 | |01:53 | ||
| − | + | |નોંધ: હેશ ની કી એક્સેસ કરવા માટે '''dollar''' ચિન્હનો ઉપયોગ કરાવાય છે. | |
|- | |- | ||
| Line 153: | Line 153: | ||
|- | |- | ||
|02:40 | |02:40 | ||
| − | | | + | |કી ડીલીટ કરવા માટે ''' delete dollar hashName open curly bracket''' |
|- | |- | ||
| Line 161: | Line 161: | ||
|- | |- | ||
| 02:53 | | 02:53 | ||
| − | | | + | | હવે સેમ્પલ પ્રોગ્રામ વાપરીને આ સમજીએ. |
|- | |- | ||
| 02:58 | | 02:58 | ||
| − | | | + | |. મેં પહેલા થી જ ''' hashKeyOperations dot pl''' ફાઈલમા કોડ ટાઈપ કયો છે. |
|- | |- | ||
| 03:05 | | 03:05 | ||
| − | | | + | | આ રીતે હેશ ડીકલેર કરાય છે. |
|- | |- | ||
|03:08 | |03:08 | ||
| − | | | + | | આપણે હેશમાંથી કીને ઉમેરીશું અને કાઢીશું |
|- | |- | ||
| 03:13 | | 03:13 | ||
| − | | | + | | અહી પહેલાથીજ બનાવેલ હેશમા કી ઉએરીએ છીએ. |
|- | |- | ||
| 03:18 | | 03:18 | ||
| − | | | + | | આ વેરીએબલને વેલ્યુ અસાઇન કરવાની જેમ જ છે. |
|- | |- | ||
|03:23 | |03:23 | ||
| − | |''' delete''' | + | |''' delete''' કીવર્ડ ને કે ને ડીલીટ કરવામાટે વાપરવામાં આવે છે. |
|- | |- | ||
|03:27 | |03:27 | ||
| − | | | + | |ડીલીટ કરવા માટે આપણને કી પાસ કરવી જોઈએ. |
|- | |- | ||
| 03:31 | | 03:31 | ||
| − | | | + | | ફાઈલ સેવ કરવા માટે ''' Ctrl+S''' દબાઓ. |
|- | |- | ||
|03:35 | |03:35 | ||
| − | | | + | | ટર્મિનલ પર જાઓ અને પર્લ સ્ક્રીપ્ટ આપેલ રીતે એક્ઝીક્યુટ કરો. |
|- | |- | ||
| Line 205: | Line 205: | ||
|- | |- | ||
| 03:44 | | 03:44 | ||
| − | | | + | | અને ''' Enter.''' દબાઓ. |
|- | |- | ||
| 03:47 | | 03:47 | ||
| − | | | + | | આઉટપુટ ટર્મિનલ પર દેખાશે. |
|- | |- | ||
| 03:52 | | 03:52 | ||
| − | | | + | |ચાલો હેશ કી અને વેલ્યુ સોર્ટ કરવાનું જોઈએ. |
|- | |- | ||
| 03:57 | | 03:57 | ||
| − | | | + | | કી સોર્ટ કરવાનું સિન્ટેક્સ છે. |
|- | |- | ||
| Line 225: | Line 225: | ||
|- | |- | ||
|04:07 | |04:07 | ||
| − | | | + | | તેમજ હેશ વેલ્યુ સોર્ટ કરવા માટે |
|- | |- | ||
| Line 233: | Line 233: | ||
|- | |- | ||
|04:18 | |04:18 | ||
| − | | | + | |સોર્ટીંગની ફ્ન્ક્શનાલીટી સેમ્પલ પ્રોગામ દ્વારા સમજીને લઇએ. |
|- | |- | ||
|04:24 | |04:24 | ||
| − | | | + | | ''' gedit.''' પર ''' sortHash dot pl''' ફાઈલ પર જાઓ. |
|- | |- | ||
Revision as of 16:46, 13 October 2014
| Time | Narration |
| 00:01 | પર્લમા હેશ પરનાં સ્પોકન ટ્યુટોરીયલમાં સ્વાગત છે. |
| 00:05 | આ ટ્યુટોરીયલમાં આપણે આપેલવિશે શીખીશું; ; |
| 00:09 | પર્લમાં હેશ અને |
| 00:11 | હેશના એલિમેન્ટને એક્સેસ કરતા. |
| 00:14 | For this tutorial, I am using અહીહું વાપરી રહ્યી છું , |
| 00:16 | ઉબુન્ટુ લીનક્સ 12.04 ઓપરેટીંગ સીસ્ટમ |
| 00:21 | અને પર્લ Perl 5.14.2 |
| 00:24 | gedit ટેક્સ્ટ એડીટર |
| 00:26 | તમે તમારા પસંદનું કોઈપણ ટેક્સ્ટ એડીટર વાપરી શકો છો. |
| 00:30 | તમને પર્લમાં વેરીએબલ અને ડેટા સ્ટ્રક્ચરની સામાન્ય જાણકારી હોવી જોઈએ. |
| 00:38 | કમેન્ટસ,લૂપ્સ,અને કન્ડીશનલ સ્ટેટમેંટ અને એરેની જાણકારી હોવી ફાયદા કારક છે. |
| 00:46 | સ્પોકન ટ્યુટોરીયલ વેબસાઈટ પર સંદર્ભિત સ્પોકન ટ્યુટોરીયલોનો સંદર્ભ લો. |
| 00:52 | હેશએ અવ્યવસ્થિત ડેટાનું સંગ્રહ છે. |
| 00:56 | આ key/value આવા જોડીના ડેટાસ્ટ્રક્ચર છે. |
| 00:59 | Hash keys વિશિષ્ટ છે. |
| 01:01 | પરંતુ હેશ ડુપ્લિકેટ વેલ્યુ ધરાવી શકે છે. |
| 01:05 | હેશ આરીતે ડીકલેર કરી શકાવાય છે. |
| 01:08 | ચાલો હવે હેશ માથી કીની વેલ્યુ કેવી રીતે મેળવવી તે જોઈએ. |
| 01:12 | કી ની વેલ્યુ મેળવવા માટે સિન્ટેક્સ છે. |
| 01:17 | dollar hashName open curly bracket single quote keyName single quote close curly bracket |
| 01:26 | સેમ્પલ પ્રોગ્રામ વાપરીને હેશને સમજીએ. |
| 01:31 | gedit. મા perlHash dot pl ફાઈલ મા કોડ પહેલા થીજ ટાઈપ કર્યો છે. |
| 01:37 | perlHash dot pl ફાઈલમા દેખાડ્યા પ્રમાણે કોડ ટાઈપ કરો. |
| 01:42 | ' પર્લમા હેશ percentage ચિન્હ સાથે ડીકલેર થાય છે. |
| 01:47 | આ હેશ ની કીઓ છે. |
| 01:49 | અને આ હેશની વેલ્યુઓ છે. |
| 01:53 | નોંધ: હેશ ની કી એક્સેસ કરવા માટે dollar ચિન્હનો ઉપયોગ કરાવાય છે. |
| 01:59 | ફાઈલ સેવ કરવા માટે Ctrl + S દબાઓ. |
| 02:02 | ટર્મિનલ પર જાઓ અને પર્લ સ્ક્રીપ્ટ એક્ઝીક્યુટ આપેલ રતે કરો. |
| 02:08 | perl perlHash dot pl |
| 02:11 | અને Enter એન્ટર દબાઓ. |
| 02:14 | ટર્મિનલ પર આઉટપુટ દેખાય છે. |
| 02:19 | ચાલો હવે હેશ માંથી કીને ઉમેરતા અને કાઢતા જોઈએ |
| 02:24 | કી ઉમેરવા માટે સિન્ટેક્સ છે. |
| 02:26 | dollar hashName open curly bracket |
| 02:30 | single quote KeyName single quote |
| 02:34 | close curly bracket equal to $value semicolon |
| 02:40 | કી ડીલીટ કરવા માટે delete dollar hashName open curly bracket |
| 02:46 | single quote KeyName single quote close curly bracket semicolon |
| 02:53 | હવે સેમ્પલ પ્રોગ્રામ વાપરીને આ સમજીએ. |
| 02:58 | . મેં પહેલા થી જ hashKeyOperations dot pl ફાઈલમા કોડ ટાઈપ કયો છે. |
| 03:05 | આ રીતે હેશ ડીકલેર કરાય છે. |
| 03:08 | આપણે હેશમાંથી કીને ઉમેરીશું અને કાઢીશું |
| 03:13 | અહી પહેલાથીજ બનાવેલ હેશમા કી ઉએરીએ છીએ. |
| 03:18 | આ વેરીએબલને વેલ્યુ અસાઇન કરવાની જેમ જ છે. |
| 03:23 | delete કીવર્ડ ને કે ને ડીલીટ કરવામાટે વાપરવામાં આવે છે. |
| 03:27 | ડીલીટ કરવા માટે આપણને કી પાસ કરવી જોઈએ. |
| 03:31 | ફાઈલ સેવ કરવા માટે Ctrl+S દબાઓ. |
| 03:35 | ટર્મિનલ પર જાઓ અને પર્લ સ્ક્રીપ્ટ આપેલ રીતે એક્ઝીક્યુટ કરો. |
| 03:40 | perl hashKeyOperations dot pl |
| 03:44 | અને Enter. દબાઓ. |
| 03:47 | આઉટપુટ ટર્મિનલ પર દેખાશે. |
| 03:52 | ચાલો હેશ કી અને વેલ્યુ સોર્ટ કરવાનું જોઈએ. |
| 03:57 | કી સોર્ટ કરવાનું સિન્ટેક્સ છે. |
| 04:00 | sort open bracket keys percentage hashName close bracket semicolon |
| 04:07 | તેમજ હેશ વેલ્યુ સોર્ટ કરવા માટે |
| 04:11 | sort open bracket values percentage hashName close bracket semicolon |
| 04:18 | સોર્ટીંગની ફ્ન્ક્શનાલીટી સેમ્પલ પ્રોગામ દ્વારા સમજીને લઇએ. |
| 04:24 | gedit. પર sortHash dot pl ફાઈલ પર જાઓ. |
| 04:30 | Type the code as displayed on the screen in your sortHash dot pl file. |
| 04:36 | Here we have declared hash of address. |
| 04:41 | Here, to sort the keys we have used the sort inbuilt function, along with the keys function. |
| 04:49 | This will sort the hash keys in alphabetical order. |
| 04:54 | Similarly, we can use the sort function on values of hash. |
| 04:59 | Sorting can also be done on numeric keys and/or values. |
| 05:05 | Save the file and switch to terminal. |
| 05:09 | Execute the script by typing perl sortHash dot pl and Press Enter |
| 05:17 | The output will be as shown on the terminal. |
| 05:22 | Now, let us see how to get all keys and values of hash. |
| 05:27 | Perl provides inbuilt function to fetch all the hash keys and values. |
| 05:34 | keys function is used to retrive all the keys of hash |
| 05:40 | values function returns values of all the keys whereas |
| 05:46 | each function iterates over hash and returns key/value pair from hash |
| 05:53 | Let us understand these using a sample program. |
| 05:57 | For this, we'll use perlHash dot pl script, which we have created earlier in this tutorial. |
| 06:07 | Type the following piece of code as shown on the screen; |
| 06:12 | Let us understand the code now. |
| 06:15 | keys function on hash, returns an array which contains all keys of hash. |
| 06:22 | values function on hash returns an array of values for all keys of hash. |
| 06:30 | each function returns the key/value pair. |
| 06:34 | Here, we have used the while loop. |
| 06:36 | It will iterate over each key/value pair of hash, that is returned by each function. |
| 06:43 | Press Ctrl+S to save the file. |
| 06:48 | Now, let us execute the script on the terminal by typing |
| 06:53 | perl perlHash dot pl |
| 06:58 | And Press Enter |
| 07:01 | The following output will be seen on the terminal. |
| 07:05 | Now let us see few other ways of looping over hash. |
| 07:10 | We can use foreach loop to iterate over each key of hash. |
| 07:15 | Then perform a set of actions on the value of a key. |
| 07:20 | The syntax is as displayed on the screen. |
| 07:24 | Here, each iteration of foreach loop will assign key from hash to $variable. |
| 07:32 | Then it will use that $variable to fetch the value or to perform a set of actions. |
| 07:40 | Similarly, we can loop over hash values as shown on the screen. |
| 07:47 | We will look at sample program. |
| 07:49 | So, let me switch to loopingOverHash dot pl in gedit. |
| 07:55 | Type the following piece of code as shown in your loopingOverHash dot pl |
| 08:02 | This piece of code returns single key of hash. |
| 08:07 | Here in our case, |
| 08:09 | 1st time dollar key ($key) contains the Department as key. |
| 08:15 | In the next iteration of foreach, Name key is returned. |
| 08:21 | Note: Hash is an unordered collection of data. |
| 08:26 | So, keys returned will not be in the sequence defined at the time of creating hash. |
| 08:33 | The loop on values works in a similar way. |
| 08:38 | Press Ctrl + S to save the file. |
| 08:41 | Then, switch to terminal and execute the Perl script as |
| 08:46 | perl loopingOverHash dot pl |
| 08:50 | and press Enter. |
| 08:53 | The following output is displayed on the terminal. |
| 08:58 | Let us summarize. |
| 08:59 | In this tutorial, we learnt - |
| 09:01 | Hash in Perl and |
| 09:03 | Accessing elements of a hash |
| 09:05 | using sample programs. |
| 09:08 | Here is assignment for you - |
| 09:11 | Declare hash having student name as key |
| 09:15 | And his/her percentage as the value. |
| 09:18 | Loop over hash using keys, values and each function |
| 09:24 | Then print the percentage of each student. |
| 09:29 | Watch the video available at the following link |
| 09:32 | It summaries the Spoken Tutorial project |
| 09:37 | If you do not have good bandwidth, you can download and watch it |
| 09:42 | The Spoken Tutorial Project Team Conducts workshops using spoken tutorials |
| 09:49 | Gives certificates to those who pass an online test |
| 09:53 | For more details, please write to contact at spoken hyphen tutorial dot org |
| 10:02 | Spoken Tutorial Project is a part of the Talk to a Teacher project |
| 10:06 | It is supported by the National Mission on Education through ICT, MHRD, Government of India. |
| 10:15 | More information on this Mission is available at spoken hyphen tutorial dot org slash NMEICT hyphen Intro |
| 10:26 | Hope you enjoyed this Perl tutorial. |
| 10:30 | This is Amol signing off. |
| 10:33 | Thanks for joining. |