Maybe you can ask one of your co-workers for assistance with this script? I say that, because this script probably has been around for a while and maybe people don’t realize that it contains an error. (See below.)
It seems to me that the seek() and read() calls should both probably refer to $buf_size rather than $file_size.
If you look at perldoc seek (click on the hyperlink ...), you will see that the existing call to this function does position “relative to end-of-file.” (That’s what the ,2) is for ...) Therefore, I think that the original intent was to slurp the last 6,000 bytes (or less, if the file was shorter). Which would have been sufficient for this script’s purposes. What it is doing now is reading the entire file. And, I think, it was never intended to do that. (But the change, whenever it occurred, is now lost in the mists of time ...)
Since this is an existing script, I think it makes sense at this point to ask a co-worker, your boss, etc. to “hey, have a look at this.” The fix is easy. But, the nature of this bug ... its presence here ... is “odd,” hence worthy of higher-up attentions. The bigger-picture question before the house (but not necessarily for you) is: how and when did this script get to be this way?
| |
Thank you for your help. I replaced the $buf_size with the $file_size and it started working. But still, there is a better way to do this without first reading the entire file. I can still see possible memory issues if the files are really big. If the trailer record is the last one in the file, I could use seek() and File::ReadBackwards to get that trailer record. But I do not know how to do that yet, so I’m still learning about that function.
| [reply] |