Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: tailing the file and look for string

by sundialsvc4 (Abbot)
on Aug 06, 2014 at 02:10 UTC ( #1096381=note: print w/ replies, xml ) Need Help??


in reply to tailing the file and look for string

My blunt ... but, by no means intended to be “blunt” ... take on this is that:

You seem to have forgotten that Perl is a full-featured programming language ... not an over-glorified [Bash ...] script.   “Instead, Plan Accordingly.™”

For example:   “tailing a file” simply means:   seek( filehandle, distance, SEEK_END).   Nothing more, nothing less, no matter how “big” the file in-between might be.   We’ve been doing this sort of thing for random-access disk files since, uhh, the 1950’s.   Thus, the Perl programming language is quite able to solve this problem without resorting to any sort of “bash-script hack” metaphors ... and, so, you should do the same.

(No, I am not trying to make fun of you in a public place!!!   Please, let us herewith “put any egos aside,” and speak frankly as though we were not in-public.   I have no way of speaking that is not public.   “But, I digress™ ...”)

To solve your problem, you simply need to read “some n bytes” from the SEEK_END of the file in question, then use ordinary regular-expression logic against the buffer thusly obtained, in a loop, choosing the last match that you may find in such a loop, and taking a calculated risk that you didn’t happen to choose exactly the wrong starting-point.


Comment on Re: tailing the file and look for string
Re^2: tailing the file and look for string
by user786 (Acolyte) on Aug 06, 2014 at 02:20 UTC
    It would have been really helpful for me if you had suggested me something that would have helped me in resolving this issue. Anyways thanks!!

      It is not at all uncommon here for people to answer the question you should have asked (in their opinion) instead of the question you did ask. I'd estimate this is helpful at least 50% of the time for the OP. It is much more likely to help the next guy who finds the thread via a search.

      1 Peter 4:10

      To echo GotToBTru’s sentiment ... and, to explain myself ... I made this “sideways” suggestion to offer a very different approach to the problem:   one that does not involve using any sort of tail-command.   I fully recognize that this might not be something that you are presently interested in, and I am also not insisting that you should.   It might well not be business-sensible in this case for you to “start over.”

      Basically:   one way to tackle this requirement is to do it the way that you are doing.   This is very-much a “bash-script strategy” in the sense that the bash-script engine is not designed to be a full-featured programming tool, therefore if you want to do these things, you must avail yourself of commands such as tail and go from there.

      But, another way to do it is to write a program that fully embraces the fact that Perl is a full-featured language with complete integrated ability to seek and read random-access files.   This is an approach that has nothing-at-all to do with the one that you are now pursuing.   “In Perl, it is available to you.   That being said, it might or might not be the right thing to do.”

      And that is what prompted my response.   Yes, partly written to the “Peanut Gallery” that will at some future aeon encounter this thread.   (Perhaps, by then, as an Archaeological Curiosity.)   “Another Way To Do It.™”

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1096381]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (7)
As of 2014-12-27 04:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (176 votes), past polls