Ameyj
Ameyj

Reputation: 617

perl magic symbols -w -r and _

What does this mean in perl ?

my $dirPath = "/some/dir"
if (-d $dir_path && -r _ && -w _ )
{

}

I know what -d does but what about -w and -r and _ ?

Upvotes: 4

Views: 128

Answers (1)

redneb
redneb

Reputation: 23920

From:

-r  File is readable by effective uid/gid.
-w  File is writable by effective uid/gid.

So -r and -w test if the file is readable. The underscore is a special handle that is used to ask perl to return information about the file specified in the most recent file test, which is -d $dir_path in this case.

So your code tests whether $dir_path is a directory for which we have read & write permissions.

Upvotes: 8

Related Questions