InterviewSolution
| 1. |
How To Code In Perl To Implement The Tail Function In Unix? |
|
Answer» You have to maintain a structure to store the LINE number and the size of the file at that time eg. 1-10bytes, 2-18bytes.. you have a COUNTER to increase the number of lines to find out the number of lines in the file. once you are through the file, you will know the size of the file at any nth line, use 'sysseek' to move the file pointer BACK to that position (last 10) and then start READING till the end. You have to maintain a structure to store the line number and the size of the file at that time eg. 1-10bytes, 2-18bytes.. you have a counter to increase the number of lines to find out the number of lines in the file. once you are through the file, you will know the size of the file at any nth line, use 'sysseek' to move the file pointer back to that position (last 10) and then start reading till the end. |
|