in reply to Re: Passing file check operators to a function
in thread Passing file check operators to a function

More mods to Grandfather's code to avoid the ugly eval:
sub checkit { my ($tests, $filename) = @_; my %TestCode=( "-e" => sub{-e $_[0] } , "-w" => sub{-w $_[0] } , "-d" => sub{-d $_[0] } , ); my @testList = split ",", $tests; for (@testList){ exists $TestCode{$_} or return 0; $TestCode{$_}->($filename) or return 0; } return 1; # Passed all tests }
(Untested)

Yes, as others have shown, more optimization is possible to avoid multiple stat calls for the same file - the point of THIS post was to avoid the eval.

     "Man cannot live by bread alone...
         He'd better have some goat cheese and wine to go with it!"