-d $filename
returns true
if the file is a directory and false
otherwise. It turns out that -C
is such a flag. In Perl, these build-in flags take precedence over user-defined functions, so in your expression
1-C($n1,$k1)
, the -C
is being interpreted as a file test flag, not a minus with a function call. Personally, I think this is a bad choice, but it is the way it is, and we have to live with that.There are a number of ways to work around it. One is to put a space between the minus and the "C"; this is why your second format works. Another would be to put parentheses around the function calls, as in
1-(C($n1,$k1))
.It is actually good practice to pus spaces around operators (for readability), so if you get in the habit of that, you will not run into this issue. But I understand how it can be confusing.