Harry Putnam <[EMAIL PROTECTED]> wrote: > "Janek Schleicher" <[EMAIL PROTECTED]> writes: >> >> The underscore _ holds the results of the last stat call >> (implicitly called by the -f operator), so no unnecessary >> work needs to be done. > > I've seen that `_' crop up before > I don't understand what this means.
It's documented in perlfunc: $ perldoc -f stat [ snip ] If stat is passed the special filehandle consisting of an underline, no stat is done, but the current contents of the stat structure from the last stat or filetest are returned. Example: if (-x $file && (($d) = stat(_)) && $d < 0) { print "$file is executable NFS file\n"; } $ perldoc -f -X [ snip ] If any of the file tests (or either the "stat" or "lstat" operators) are given the special filehandle consisting of a solitary underline, then the stat structure of the previous file test (or stat operator) is used, saving a system call. > Further: > Won't your code try to process symlinks too? Of course! Everything resolves symlinks; it's got nothing to do with the magic "underscore" filehandle. Try the example code without it: if (-e $file and -f $file) { ... And you'll get the same results. You need lstat() or -l to find out any information about the symlink itself. -l $file; # does an lstat() behind the scenes -l _; # just reads values from the buffer -e $file; # calls stat() -e _; # just reads values from the buffer So... if you're paying attention you can see a problem here. if (-e $file and -l _) { ... But Perl would rather croak() than let you make that mistake and it results in a fatal error. -- Steve -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]