Shaji Kalidasan wrote:
You can use more than one file test on the same file to create a
complex logical condition.
Suppose you only want to operate on files that are both readable and
writable; you check each attribute and combine them with and:
if (-r $file and -w $file) {
...
}
Each time you perform a file test
or use stat() or lstat()
, Perl asks the filesystem for all of
the information about the file (Perl’s actually doing a stat each time,
which we talk about in the next section). Although you already got that
information when you tested -r, Perl asks for the same information
again so it can test -w. What a waste! This can be a significant
performance problem if you’re testing many attributes on many files.
The virtual filehandle _ (just the underscore) uses the information
from the last file lookup that a file test operator
or stat() or lstat()
performed. Perl
only has to look up the file information once now:
John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction. -- Albert Einstein
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/