WeBWorK Main Forum

Caret and schtick

Caret and schtick

by Philip Loewen -
Number of replies: 2

I just got burned by typing the caret ("^") into a Perl formula when I wanted some exponentiation to happen. Since ^ is a legitimate binary operator, there is no error message ... just an unexpected result.

Figuring out what I had done wrong took hours, of course. But there was a silver lining: emotional engagement deepens one's learning.

To consolidate and commemorate this educational experience, I have turned it into a WW problem, which I hereby offer to the community.

In reply to Philip Loewen

Re: Caret and schtick

by Davide Cervone -

Just an FYI, if your $two and $three had been MathObject Reals, rather than Perl reals, then $a = $two^$three would have produced the error

    Can't use '^' with Real-valued operands (use '**' for exponentiation)
In reply to Davide Cervone

Re: Caret and schtick

by Philip Loewen -
Thanks, Davide -- for this and so much more. Clearly you have done everything possible to save users like me from getting confused over this. I hope my slightly cheeky post will nudge some fellow noobs in a good direction.