Hey All, thanks for the new replies...
Sorry, but I am soo confused right now... Maybe it's because I'm at the end of my day, but I am just not grasping how this is supposed
to work? The one example that was given by roboticus, to me, almost seems like its written in reverse. I'm sure it's not because I know
you guys are the experts, but I guess I'm just totally lost here...
From what I read (*at perldoc.perl.org), it sounds like you can use 'seek' to move around the File, but in bytes or characters and not
lines (right?). Something like, you pass it a number as the second argument to seek, positive num to move forward
x bytes or
negative to move in reverse
-x bytes.
And then truncate can be used to truncate or remove portions of a file to a specific length. I also read about 'tell' which will tell you
where in the file you are currently reading from, correct
(*not sure if I need that or not..)?
If possible, could someone explain (*in psudeo-code) how exactly it SHOULD work...? Something like:
(*use open() here) - Open the filehandle FH
(*use array and FH) - Slurp all lines from FH to Array
(*use seek here) - Go to a position in the file
(*etc....)
I'm just not grasping the logic behind it I guess...
Or maybe an example. Let's say I have the File "test_file.log" containing:
COL-1 COL-2 COL-3 COL-4
Line #1
Line #2
Line #3
Line #4
Line #5
And basically, that log file should never have more then 6 TOTAL lines (*5 lines containing the data, and +1 for the Col headings), and the
newest data would be at the bottom.
And if I ran my script and added a NEW line of data to the file, the end result should be:
COL-1 COL-2 COL-3 COL-4
Line #2
Line #3
Line #4
Line #5
Line #6
I don't know if that example changes any of your understanding's of my original post, sorry if I'm being a pain... I'm just trying to grasp how
exactly seek and truncate can be used together on this...? I'm going to be heading home in a minute or 2 so maybe I'll understand better tomorrow when my head is a bit fresher...
Again, sorry for the confusion on my part, it's been a long day..!
And thanks AGAIN EVERYBODY for the replies, it is VERY much appreciated!
Thanks,
Matt