Quote:
Originally Posted by
hankooknara
2) not understanding how shift @last5 if @last5 > 5 works.. can somone let me know item by item please?
No, because it is the overall effect of the entire while() loop that causes the last 5 lines to be stored in the @last5 array variable, not due to that shift() function alone.
While each line is added to the array in each iteration, if the "shift() .... if ..." finds that more than 5 (maximum 6, actually) lines stored in the array, it will start removing a single line each time from the top so the count is maintained at 5. You can view this as a circular buffer. Of course, when the loop terminates, the items inside must be the last 5 lines read from the file (or may be less, if the file has < 5 lines).
If you still don't get it, put some print() in the loop to print the loop content in each iteration to see for yourself the change in content in action. Of course you can use debugger. Good only if you know how to use it, and the Perl debugger is, em, well .......