Difference between revisions of "PERL/C3/File-Handling/Gujarati"
From Script | Spoken-Tutorial
Jyotisolanki (Talk | contribs) |
Jyotisolanki (Talk | contribs) |
||
Line 137: | Line 137: | ||
| 03:08 | | 03:08 | ||
| '''while ''' લૂપ લાઈન બાઈ લાઈન વાંચશે અને ત્યાં શુધી '''<nowiki> <</nowiki>DATA>''' ફાઈલને લૂપ કરશે જ્યાં સુધી બધી ફાઈલ વાચી ના લેવાય. | | '''while ''' લૂપ લાઈન બાઈ લાઈન વાંચશે અને ત્યાં શુધી '''<nowiki> <</nowiki>DATA>''' ફાઈલને લૂપ કરશે જ્યાં સુધી બધી ફાઈલ વાચી ના લેવાય. | ||
− | |||
|- | |- | ||
| 03:17 | | 03:17 | ||
− | | '''Print dollar underscore''' ('$_') | + | | '''Print dollar underscore''' ('$_') વેરીએબલ વર્તમાન લાઈનની વિષય વસ્તુને પ્રિન્ટ કરશે. |
|- | |- | ||
| 03:22 | | 03:22 | ||
− | | | + | | છેલ્લે ''' FILEHANDLE''' નામના સાથે ફાઈલને બંદ કરો જે આપણે ઓપન સ્ટેટમેન્ટ માં આપ્યું હતું. |
|- | |- | ||
| 03:29 | | 03:29 | ||
− | | | + | | ફાઈલને બંદ કરવું કન્ટેન્ટનું ઓવરરાઈટ થવું અથવા ફાઈલના કોઈ પણ આકસ્મિક બદલાવોને રોકે છે. |
|- | |- | ||
| 03:36 | | 03:36 | ||
− | | | + | | હવે ફાઈલને સેવ કરવા માટે ''' Ctrl+S''' to ''' દબાવો. |
|- | |- | ||
| 03:40 | | 03:40 | ||
− | | | + | | ચાલો પ્રોગ્રામને એક્ઝીક્યુટ કરીએ. |
|- | |- | ||
| 03:42 | | 03:42 | ||
− | | | + | | ટર્મિનલ પર જાવ અને ટાઈપ કરો '''perl openfile dot pl''' અને એન્ટર દબાવો. |
|- | |- | ||
| 03:51 | | 03:51 | ||
− | | | + | | આઉટપુટ આપેલની જેમ દ્રશ્યમાન છે. |
|- | |- | ||
| 03:54 | | 03:54 | ||
− | | | + | | આ તેજ કન્ટેન્ટ છે જે આપણે '''first dot txt ''' ફાઈલમાં પહેલા જોયું હતું. |
|- | |- | ||
| 03:59 | | 03:59 | ||
− | | | + | | આગળ આપણે જોશું ફાઈલમાં ડેટા કેવી રીતે લખવા. |
|- | |- | ||
| 04:03 | | 04:03 | ||
− | | | + | | ''greater than''' (>) સિમ્બોલ ના સાથે ઓપન સ્ટેટમેન્ટ '''WRITE''' મોડમાં યાખ્યાયિત કરે છે. |
|- | |- | ||
| 04:08 | | 04:08 | ||
− | | | + | | ફાઈલનેમ તે ફાઈલના નામને બતાડે છે જે ડેટા લખવાનું છે. |
− | + | ||
|- | |- | ||
| 04:13 | | 04:13 |
Revision as of 12:53, 22 January 2016
Time | Narration |
00:01 | PERL. માં File Handling પરના આ સ્પોકન ટ્યુટોરીયલમાં સ્વાગત છે. |
00:06 | આ ટ્યુટોરીયલમાં આપણે આપણે શીખીશું:
|
00:17 | આ ટ્યુટોરીયલ માટે હું ઉપયોગ કરી રહી છું:
|
00:28 | તમે તમારી પસંદગી અનુસાર કોઈ પણ ટેક્સ્ટ એડિટર વાપરી શકો છો. |
00:32 | આ ટ્યુટોરીયલના અનુસરણ માટે તમને ' Perl પ્રોગ્રામિંગ વિષે સામાન્ય જાણકારી હોવી જોઈએ. |
00:37 | જો નથી તો સ્પોકન ટ્યુટોરિયલ વેબ સાઈટ પર ઉપલબ્ધ Perl ટ્યુટોરિયલ જુઓ. |
00:43 | મૂળભૂત ઓપરેશન જે આપણે પર્લમાં ફાઈલ્સ સાથે કરી શકીએ છીએ તે છે:
|
00:54 | file handles are: મૂળભૂત file handles છે.
|
01:02 | આ open ફંકશન માટે સિન્ટેક્સ છે. |
01:05 | સિન્ટેક્સમાં FILEHANDLE એ ફાઈલ હેન્ડલ છે જે open ફંકશન થી રીટર્ન થાય છે. |
01:11 | MODE ફાઈલ ખોલવું જેવા: રીડ, રાઈટ વગેરે મોડ ને બતાડે છે. |
01:18 | EXPR એ ભૌતિક ફાઈલનનું નામ છે જે વાંચવા અને લખવામાં ઉપયોગ થાય છે. |
01:27 | અહી પ્રદશિતની જેમ open ફંકશન ને લખવા માટે અન્ય માર્ગ છે. |
01:32 | ચાલો સમઝીએ વર્તમાન ફાઈલને કેવી રીતે ખોલવી અને તેમાંથી ડેટા કેવી રીતે વાંચવા. |
01: | પ્રથમ આપણે એક ટેક્સ્ટ ફાઈલ બનાવીશું અને તેમાં અમુક ડેટા સંગ્રહીશું.ટર્મિનલ પર જાવ અને ટાઈપ કરો gedit first.txt અને એન્ટર દબાવો. |
01:51 | first dot txt ફાઈલમાં આપેલ ટેક્સ્ટ ટીપ કરો: |
01:55 | ફાઈલ ને સેવ કરીને gedit બંદ કરો. |
01:59 | હવે આપણે એક Perl પ્રોગ્રામ જોશું જે first.txt ફાઈલ ખોલે છે અને વિષય વસ્તુ વાંચે છે. |
02:07 | હવે હું openfile.pl સેમ્પલ પ્રોગ્રામ ખોલીશ. જે મેં પહેલાથી જ સેવ કરેલ છે. |
02:13 | ટાઈપ કરો : gedit openfile dot pl ampersand અને એન્ટર દબાવો. |
02:19 | openfile dot pl ફાઈલમાં,સ્ક્રીન પર પ્રદશિત આપેલની જેમ કોડ ટાઈપ કરો. |
02:25 | ચાલો હું કોડ સમજાવું. |
02:28 | The open ફંકશન વાંચવા માટે એક ફાઈલ ખોલે છે. |
02:33 | પ્રથમ ડેટા ફાઈલ હેન્ડલ છે જે ભવિષ્યમાં ફાઈલ અનુસરણ કરવાની પરવાનગી આપે છે. |
02:40 | બીજું પેરામીટર “<” લેસ ધેન સિમ્બોલને READ મોડ માં દર્શાવે છે. |
02:44 | જો તમે Mode, સ્પષ્ટ કરવામાં ચૂંકી જાવ તો ડીફોલ્ટ રૂપે ફાઈલ “READ” મોડમાં ખોલવામાં આવશે. |
02:50 | ત્રીજું પેરામીટર first.txt એ ફાઈલનું નામ છે જ્યાંથી ડેટા વાંચવાનું છે. |
02:57 | શું થશે જો first.txt ફાઈલ અસ્તિત્વના હોય ? |
03:02 | સ્ક્રીપ્ટનો યોગ્ય error message સાથે અંત થશે dollar exclamation ($!) વેરીએબલમાં સંગ્રહિત થશે. |
03:08 | while લૂપ લાઈન બાઈ લાઈન વાંચશે અને ત્યાં શુધી <DATA> ફાઈલને લૂપ કરશે જ્યાં સુધી બધી ફાઈલ વાચી ના લેવાય. |
03:17 | Print dollar underscore ('$_') વેરીએબલ વર્તમાન લાઈનની વિષય વસ્તુને પ્રિન્ટ કરશે. |
03:22 | છેલ્લે FILEHANDLE નામના સાથે ફાઈલને બંદ કરો જે આપણે ઓપન સ્ટેટમેન્ટ માં આપ્યું હતું. |
03:29 | ફાઈલને બંદ કરવું કન્ટેન્ટનું ઓવરરાઈટ થવું અથવા ફાઈલના કોઈ પણ આકસ્મિક બદલાવોને રોકે છે. |
03:36 | હવે ફાઈલને સેવ કરવા માટે Ctrl+S to દબાવો. |
03:40 | ચાલો પ્રોગ્રામને એક્ઝીક્યુટ કરીએ. |
03:42 | ટર્મિનલ પર જાવ અને ટાઈપ કરો perl openfile dot pl અને એન્ટર દબાવો. |
03:51 | આઉટપુટ આપેલની જેમ દ્રશ્યમાન છે. |
03:54 | આ તેજ કન્ટેન્ટ છે જે આપણે first dot txt ફાઈલમાં પહેલા જોયું હતું. |
03:59 | આગળ આપણે જોશું ફાઈલમાં ડેટા કેવી રીતે લખવા. |
04:03 | greater than' (>) સિમ્બોલ ના સાથે ઓપન સ્ટેટમેન્ટ WRITE મોડમાં યાખ્યાયિત કરે છે. |
04:08 | ફાઈલનેમ તે ફાઈલના નામને બતાડે છે જે ડેટા લખવાનું છે. |
04:13 | Let me open the sample program 'writefile.pl' which I have already saved. |
04:19 | Switch to the terminal. |
04:21 | Now, type: gedit writefile dot pl ampersand and press Enter. |
04:29 | In the writefile dot pl file, type the following code as displayed on the screen. |
04:34 | Let me explain the code now. |
04:37 | The open function opens a file 'second.txt' in "write" mode. |
04:44 | “>” - Greater than symbol before the filename denotes the "write" mode. |
04:49 | The first parameter "FILE1" is the FILEHANDLE. |
04:53 | The print function prints the given text to FILEHANDLE. i.e 'FILE1'. |
04:59 | Now, press Ctrl+S to save the file. |
05:03 | Let us execute the program. |
05:05 | Switch back to the terminal and type: perl writefile dot pl and press Enter. |
05:12 | Now, let us check whether the text has been written in 'second.txt' file. |
05:18 | Type: gedit second.txt and press Enter. |
05:23 | We can see the text: "Working with files makes data storage and retrieval a simple task!" in our 'second.txt' file. |
05:32 | Let us close the 'second.txt' file. |
05:35 | What will happen if we open the same file again in "write" mode? Let us see that. |
05:41 | In the 'writefile.pl', comment the previous print Statement. |
05:46 | Add the below print command. |
05:48 | Now, press Ctrl+S to save the file. Let us execute the program. |
05:54 | Switch back to the terminal and type perl writefile dot pl and press Enter. |
06:00 | Now, let us check the 'second.txt' file once again. |
06:04 | Type: gedit second.txt and press Enter. |
06:09 | We can see the output: “Greater than symbol (>) overwrites the content of the file!" |
06:14 | The previous contents of the 'second.txt' file has been overwritten. |
06:19 | This is because, we had opened the file in the "write" mode again. |
06:24 | Let us close the 'second.txt' file. |
06:27 | Next, we will see how to append data to an existing file. |
06:32 | The open statement with two greater than (>>) symbols denotes the "APPEND" mode. |
06:38 | Now I will open the writefile dot pl again in gedit. |
06:44 | In the open statement, type two greater (>>) than symbols. This will denote that the file is in append mode. |
06:52 | Comment the previous print statement, as it is already executed. |
06:57 | Add the line: print FILE1 within double quotes "Two greater than symbols (>>) open the file in append mode", to append to the existing data. |
07:07 | Now, press Ctrl+S to save the file. |
07:11 | Let us execute the program. |
07:14 | Switch back to the terminal and type: perl writefile dot pl and press Enter. |
07:20 | Now, let us check whether the text has been appended to the 'second.txt' file. |
07:26 | Type: gedit second.txt and press Enter. |
07:31 | We can see the text has been appended in our 'second.txt' file. |
07:36 | Let us close the 'second.txt' file. |
07:39 | Similarly, there are other modes also. |
07:42 | Try out these options on your own and understand what happens. |
07:49 | This brings us to the end of this tutorial. Let us summarize. |
07:53 | In this tutorial, we learnt to:
|
08:03 | Here is an assignment for you. Change the file attribute to "+>" in the 'writefile.pl' program. |
08:11 | Save and execute the program. |
08:14 | Open the 'second.txt' file to see the output. |
08:17 | Analyze the usage of file attribute "+>". |
08:22 | The video at the following link summarizes the Spoken Tutorial project. Please download and watch it. |
08:29 | The Spoken Tutorial Project team:
|
08:37 | For more details, please write to us. |
08:41 | Spoken Tutorial project is funded by NMEICT, MHRD, Government of India. |
08:48 | More information on this mission is available at this link. |
08:53 | This is Nirmala Venkat from IIT Bombay, signing off. Thanks for watching. |