So we're talking about Perl and he asks "how do I read a file, change it, and write it back out again? Do I have to close and reopen it?"
There are many different ways to do this and the best choice depends upon what you need to do, who else might be using the file, the size of the file, etc. Since many of his questions are standard questions I suggested he pick up a copy of the Perl Cookbook.
I then backpedalled (sp?) furiously. The Second Edition of the book should be out in August. I'll just loan him an extra copy and, in the meantime, drool in anticipation at the thought of the second one.
Excuse me now. I have to go wipe the saliva off my chin.
In general, if your file is line-based, you are probably best off using Tie::File; if you need to change characters (bytes) at a specific location in the file, then you probably want to use things like seek, tell, and the update file open option.
I put this here not because Ovid doesn't know it, but in case anyone was reading and wondering.
I was hoping you'd have him buy two copies
Second edition should be out in September, assuming we survive QC1. I have the first 17 chapters, and it's already 746 pages long. TOO
--Nat
Re:Nuts!
chaoticset on 2003-07-17T20:25:57
I wait with great anticipation for the second edition of the Ram. (What I'd really like to see someday is a Complete Perl Bookshelf, up-to-date editions of every book that's been on one of the Shelves. Wouldn't even need a physical copy of the Nutshell, because this would be an item for people who presumably owned a copy of it already. I suspect it's not even close to feasible, but I figured I'd ask while I'm here.Too much Perl: A statement that, given any reasonable definition of those three words, cannot possibly make sense.:) ) Re:Nuts!
gnat on 2003-07-17T21:03:04
You mean a CD-ROM or a big ole pile of books?
--Nat
Re:Nuts!
chaoticset on 2003-07-18T02:17:41
You're just toying with me now, aren't you?I meant the CD-ROM, of course...
Re:Nuts!
gizmo_mathboy on 2003-07-21T18:10:29
Bookshelf! Bookshelf! Bookshelf!
It would be fantastically awesome to have "The Compleat Perl CD Bookshelf". Then again owning just about every CD Bookshelf O'Reilly has I can sort of roll my own.
Hmmm, how does Perldor the Perlinator sound?
Perldor! Perldor!
Regexing the countryside. Sexegering the peasants!
Maybe I'll stop there...don't want to offend Trogdor anymore than I have to.;-)