Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

perl magic symbols -w -r and _

Tags:

perl

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

like image 890
Ameyj Avatar asked Feb 07 '23 05:02

Ameyj


1 Answers

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.

like image 189
redneb Avatar answered Mar 08 '23 11:03

redneb