|
Posted by John W. Krahn on March 26, 2008, 8:18 pm
Please log in for more thread options
Michael Slass wrote:
> I was looking at the standard module lib.pm, and saw this puzzling (to
> me) bit:
>=20
> foreach (reverse @_) {
> my $path =3D $_; # we'll be modifying it, so break the alias
> if ($path eq '') {
> require Carp;
> Carp::carp("Empty compile time value given to use lib");
> }
>=20
> $path =3D _nativize($path);
>=20
> if (-e $path && ! -d _) {
> require Carp;
> Carp::carp("Parameter to use lib must be directory, not file");
> }
>=20
> What does the _ with no sigil before it mean in
> if (-e $path && ! -d _) {
perldoc -f -d
[ 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. (This
doesn=92t work with "-t", and you need to remember that lstat()
and "-l" will leave values in the stat structure for the
symbolic link, not the real file.) (Also, if the stat buffer
was filled by an "lstat" call, "-T" and "-B" will reset it with
the results of "stat _"). Example:
print "Can do.\n" if -r $a || -w _ || -x _;
stat($filename);
print "Readable\n" if -r _;
print "Writable\n" if -w _;
print "Executable\n" if -x _;
print "Setuid\n" if -u _;
print "Setgid\n" if -g _;
print "Sticky\n" if -k _;
print "Text\n" if -T _;
print "Binary\n" if -B _;
John
--=20
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
|