YAPC day 2: Tie::File

jdavidb on 2002-06-27T18:04:31

I think I'm going to wind up seeing all of MJD's presentations. Actually, I considered going to on-topic or back to mod_perl just for more variety. MJD's good, though, so it's not like I'm suffering. To be honest, I think I could probably --

That's funny. MJD just told Simon to leave since he wasn't saying anything interesting. I'm not saying I know as much as Simon, but I would have left if he did. I was really just here because this was the most convenient room for me to plug into the network. :)

Tie::File. Easy. Tie an array to a file; now the array is the lines of your file. I've never done this, but I wanted to. As I was going to say, I could probably figure this out from the documentation. Or MJD's slides, conveniently available in the orange YAPC book.

You could rewrite grep very easily with Tie::File: use Tie::File;
#tie the file; I didn't see how to do that; you can read the docs
grep $pattern, @file_lines

"$#array is kind of a drag, but Larry did it to us." I forgave him, and I'm sure it will be fixed in Perl 6.

I wish I had wireless just so I could pull and install modules as they are mentioned.

Tie::File does allow for concurrent access, since changes are pretty much done immediately. DB_File reads everything into memory, so you can have race conditions if you try concurrent access. File locking management with Tie::File is on the way. (0.96 should be out next month.)

Tie::File does caching. LRU.

Apparently Tie::File does everything I'd want it to in the way I want it to. It's just that I've never felt like putting that much work into the rushed programs I'm always having to produce, and this is in a module.

Tie::File is pure Perl.

Lines in a tied file are chomped, but if you put a newline at the end of an element it will realize and not add another when it writes out the file. However, if you add newlines in the middle of a line, you should be aware of what you're doing. <rant ranter="me, not mark">READ THE DOCS AND DON'T GIVE US 19100 LOCALTIME BUG REPORTS ALL OVER AGAIN, PLEASE!!</rant> (I still can't believe how many people just blindly used that function without reading the docs. I wouldn't use it until I knew what it DID.) So the answer is, don't do that. Good answer.

The smiling baby at the end of some of MJD's slides was found by searching Google for "happy baby." :)

You can't @F = sort @F; and there's nothing that can be done. Yet.

Simon left with about ten minutes left. But not before suggesting Mark investigate using mmap. This was kind of a talk where anyone could have figured out the module themselves, I think, but we did get to talk about how some features should work and implementation and so on. After the mailing list judo talk I'm definitely reluctant to make suggestions publicly for fear of being identified as a peanut gallery member (I'm trying to keep that a secret. Until it's not true anymore.)