Harry Putnam <[EMAIL PROTECTED]> wrote: > Steve Grazzini <[EMAIL PROTECTED]> writes: >> Harry Putnam <[EMAIL PROTECTED]> wrote: >>> >>> I've seen that `_' crop up before >>> I don't understand what this means. >> >> It's documented in perlfunc: > > Yes, I saw it there too. I must be having a particularly dense > time of it, but I still am missing what is actually in _
Nothing's in it. It's just a filehandle. If you call stat() or use a file test operator on an ordinary filehandle, Perl uses the fstat() system call: if (-t STDOUT) { # connected to terminal If you call stat() or use a file test operator on the special _ filehandle, perl *skips the system call* and returns the results of the previous stat() (or lstat() or fstat()) system call, which have been squirreled away somewhere. There's nothing in the _ filehandle; it's just a signal to perl that we want to reuse those cached results. > The previous content of the stat structure is what? (in plain > english) Does it mean the previous values of the 13 elements > produced by stat? Something like that. The 'stat structure' is the big C struct described in the stat(2) manpage. The perl interpreter has one of these as a sort of global variable. When you do "stat $file", perl makes the stat system call, which populates this struct. The values in the structure are left there afterward, and when you do "stat _", perl skips the system call and reuses whatever is already in the struct. There are two principles at work (1) system calls are relatively expensive: so we want to cache the results of stat() if we need to do more than one file test on the same file/filehandle. (2) the file test operators (e.g. '-f _') are much more convenient than the S_ISWHATEVER macros or their equivalent bit-shifting: so we'd prefer to let perl do the caching for us internally. -- Steve -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]