
problem using eval with array of file test operators
Hi. I am trying to write a method which prints out the status of a
file using the file test operators. The code is shown below. I am
having a problem trying to figure out how to set up the command text
string and using eval. I keep getting the error 'Scalar found where
operator expected at (eval 50) line 1, at end of line (#2)'. The
operation never failes either, even though the tests are mutually
exclusive.
Please someone explain this to me.
Curtis
================================================================
sub file_tests
{
my $self = shift;
['-r', "File is %s readable by effective uid\n" ],
['-w', "File is %s writable by effective uid\n" ],
['-x', "File is %s executable by effective uid\n" ],
['-o', "File is %s owned by effective uid\n" ],
['-R', "File is %s readable by real uid\n" ],
['-W', "File is %s writable by real uid\n" ],
['-X', "File is %s executable by real uid\n" ],
['-O', "File is %s owned by real uid\n" ],
['-e', "File does %s exist\n" ],
['-z', "File does %s have zero size\n" ],
['-s', "File does %s have zero non-size\n" ],
['-f', "File is %s a plain file\n" ],
['-d', "File is %s a directory\n" ],
['-l', "File is %s a symbolic link\n" ],
['-S', "File is %s a socket\n" ],
['-p', "File is %s a named pipe\n" ],
['-b', "File is %s a block file\n" ],
['-c', "File is %s a character special file\n" ],
['-u', "File does %s have setuid bit set\n" ],
['-g', "File does %s have setgid bit set\n" ],
['-k', "File does %s have sticky bit set\n" ],
['-t', "Filehandle is %s opened to a tty\n" ],
['-T', "File is %s a text file\n" ],
['-B', "File is %s a binary file\n" ]
);
my( $ftest, $result, $qualifier, $ratest, $command );
$ftest = $$ratest[0];
$result = $$ratest[1];
$command =
'if ( $ftest $fname ) {
$qualifier = "";
} else {
$qualifier = "not";
}';
print "Command is $command\n";
eval $command ;
printf($result, $qualifier);
}
Quote:
}