in reply to File testing via list of test operators

I think if you print out the actual string you are passing to eval the answer to your question will be obvious.

Replies are listed 'Best First'.
Re^2: File testing via list of test operators
by robh (Initiate) on Dec 21, 2010 at 14:32 UTC
    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! :)
      eval{"$cmd"}
      That's true if "$cmd" is true. If you want to evaluate $cmd, then write:
      eval $cmd

      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.