in reply to Re: File testing via list of test operators
in thread File testing via list of test operators

Hi - thanks for the prompt replies. After making the changes i.e.
foreach my $t (keys %tests) { my $cmd="$t '$myfile'"; print "running [$cmd]\n"; if ( eval{"$cmd"} )
Perl now says ...
running [-r './test.pl'] Passed [-r] test, ./test.pl is (is readable) running [-T './test.pl'] Passed [-T] test, ./test.pl is (type Text) running [-z './test.pl'] Passed [-z] test, ./test.pl is (is Zero bytes) running [-B './test.pl'] Passed [-B] test, ./test.pl is (is Binary) running [-s './test.pl'] Passed [-s] test, ./test.pl is (more than 0 bytes)
So my script is a 0 byte file and also a > 0 byte file. Cool! :)

Replies are listed 'Best First'.
Re^3: File testing via list of test operators
by JavaFan (Canon) on Dec 21, 2010 at 14:48 UTC
    eval{"$cmd"}
    That's true if "$cmd" is true. If you want to evaluate $cmd, then write:
    eval $cmd
Re^3: File testing via list of test operators
by ELISHEVA (Prior) on Dec 21, 2010 at 15:03 UTC

    Great catch JavaFan!

    You can also get contradictory answers, in this case, both -s and -z returning false, if ./test.pl does not exist. It clearly isn't your problem here, but if you are applying this sequence of tests to arbitrary files, you might want to do the test for existence separately before passing the file through the gauntlet of your hashed up tests.