On Tue, Dec 29, 2009 at 8:27 PM, Steve Bertrand <st...@ibctech.ca> wrote:
> Happy holidays everyone! > > I've found Devel::Cover to be an exceptionally handy item, but don't > think I entirely grasp what the term 'short-circuiting' actually means. > I'm not familiar with Devel::Cover. The phrase "short circuit" usually refers to the boolean operators && and ||. Perl stops evaluating boolean operations as soon as it can. For example, take this code: if ($true || $false) { print "True\n"; } The || operator evaluates as true whenever at least one condition evaluates true. Perl grabs the left hand side: $true. It sees a true value and prints the line. Perl never looks at $false because the value of $false doesn't matter. Now consider this example: if (do_first(1, 2) || do_second(\$result)) { print "True\n"; } Assume do_first returns true and the line prints. What about $result? Perl never called into the code for do_second, and $result never changed. We say that Perl short circuited the evaluation. It stopped executing code as soon as it knew the outcome of the logic statement. -- Robert Wohlfarth