in reply to Text Processing

I just recently discovered some functions that are good for this sort of thing. seek() and tell(). tell(FILE) will return your current position in the file FILE, and seek(FILE, $n, 0) will send you to the location in FILE stored in $n. Use them like this:
# open your file $top_of_file = tell(FILE); # go fetch your variable seek(FILE, $top_of_file, 0); # now you're back at the top
They're handy in other situations, too. You can tell() any number of positions in the file, and go back to them at will. I bet there's a JAPH in that concept somewhere...

---
I'm too sexy for my .sig.

Replies are listed 'Best First'.
Re: Re: Text Processing
by arturo (Vicar) on Apr 21, 2001 at 00:55 UTC

    Silly ol' me forgot about tell in my response (I used that inelegant length thing). Oh well; I just wanted to register the caveat that you must read in the first line *before* you do the call to tell, otherwise you get the uninformative result 0.

      But isn't that the very beginning of the file? Or is that not where we want to be?

      ---
      I'm too sexy for my .sig.

        Well, if you did, then why bother making the function call? =)

        My understanding is that the original poster (gah, forget the name, sorry) wants to print out a new first line, then keep every line thereafter. I was shoehorning it into my framework.