The following does what you would like, although I'd not recommend this as anything other than a learning exercise. In particular if (-e $filename && -w _) is more efficient than hitting on the file system for each test.
use strict; use warnings; my $filename = "c:\\myfile.txt"; checkit ("-e,-w", $filename) ? print "File $filename exists and is writeable" : print "File $filename does not exist or is not writeable"; sub checkit { my ($tests, $filename) = @_; my @testList = split ",", $tests; for (@testList) { return 0 if ! eval ("$_ '$filename'"); } return 1; }
Note that eval is used to perform the actual test and split is used to generate a list of tests to be performed.
In reply to Re: Passing file check operators to a function
by GrandFather
in thread Passing file check operators to a function
by smartnezz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |