WeBWorK Main Forum

using n choose k

Re: using n choose k

by Davide Cervone -
Number of replies: 0
The issue is that Perl has a number of "file test flags" (see this list) that are modeled on unix command-line arguments for checking if certain files match certain conditions. For example, -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.