Ameyj Ameyj - 8 months ago 72
Perl Question

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 _ ?



-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 $dirPath is a directory for which we have read & write permissions.