A
Avner
I want to create a parametrized check of the file type. Something like:
return unless -f $_
where the -f may be changed to -d in a different scenario. So I create
a variabled string and apply eval to the string:
e.g.
$fileType = "-f";
$cmdLine = "return unless $fileType $_";
print "cmdLine: $cmdLine\n";
eval $cmdLine;
If I type the "return unless -f $_" the perl code acts correctly but if
creating a variabled string and appling eval to it the code fails.
Printing the cmdLine looks ok (it prints to the screen "cmdLine: return
unless -f ." where . is the checked file
but then I get the following error from the eval line
Warning: Use of "-f" without parens is ambiguous at (eval 1) line 1.
Error code: syntax error at (eval 1) line 2, at EOF
What's wrong?
Thanks,
Avner
return unless -f $_
where the -f may be changed to -d in a different scenario. So I create
a variabled string and apply eval to the string:
e.g.
$fileType = "-f";
$cmdLine = "return unless $fileType $_";
print "cmdLine: $cmdLine\n";
eval $cmdLine;
If I type the "return unless -f $_" the perl code acts correctly but if
creating a variabled string and appling eval to it the code fails.
Printing the cmdLine looks ok (it prints to the screen "cmdLine: return
unless -f ." where . is the checked file
but then I get the following error from the eval line
Warning: Use of "-f" without parens is ambiguous at (eval 1) line 1.
Error code: syntax error at (eval 1) line 2, at EOF
What's wrong?
Thanks,
Avner