checkDir('/usr/tmp', sub { -w shift }); # need write permission. checkDir('/usr/tmp', sub { -r shift }); # need read permission. checkDir('/usr/tmp', sub { my $x = shift; -r $x and -w $x; }); # need both. checkDir('/usr/tmp', sub { my $x = shift; not $x =~ /\.\./; }); # safety check. sub checkDir { my ($path, $perm) = @_; ### Check if output dir exists if (! defined $path) { LOG ("Output path not defined; using temp instead...", 1); $path = '/var/tmp/'; } if (! -d $path) { die LOG ("$path is not a valid directory...", 0); } if (! $perm->($path)) { die LOG ("Test failed on $path, not able to use it.", 0); } LOG ("Using $path as output directory...", 2); }