Well, I don't want to over-explain since the best way to learn is often to figure things out for yourself. However, let's examine what I suppose could be the 2 most confusing parts.
ask ($operands[0] > $operands[1], @operands);
This is a subroutine call. You'll see we've defined the subroutine ask in the script? This is how it is called. There are either 2 or 3 arguments inside the brackets depending on how you see things. The first one is $operands[0] > $operands[1] which is a logical expression and therefore either true or false and the second one is @operands which is an array with the 2 random values previously assigned. Note that originally this line had an @ symbol at the start of $operands[0] which although OK was misleading (and a typo) so I've corrected it now.
my $answer = $subtract ? $args[0] - $args[1] : $args[0] + $args[1];
This is a variable assignment which computes the answer in one way or another depending on the logical value in $subtract which we passed into the sub as the first argument. It uses the ternary operator which is of the form condition ? eval-if-true : eval-if-false. Think of it as a short-hand way of writing an if-else block.
The rest of the code is just loops and prints, really. See if you can trace through the logic now.
|