Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • But "if" cannot be replaced by "unless" and vice versa in every case. Witness:
    sub using_if {
      $value = 3;
      "bogus" if not $value;
    sub using_unless {
      $value = 3;
      "bogus" unless $value;
    my $result_if = using_if(); # will be "false" (result of "not $value")
    my $result_unless = using_unless(); # will be 3 (result of $value)
    A similar dichotomy results from "while" vs "until". So, both are needed.
    • Randal L. Schwartz
    • Stonehenge
  • Since I am trying to get my code inline with "Perl Best Practices", "unless" is discouraged.
  • "Branches with positive branch offsets (downwards) are considered to be likely not taken, that is the fall-through case is the default one."

    Yup, this comes down to branch prediction in the CPU which is one of many performance tricks they do. You've probably guessed this, but they also expect that branches with negative branch offsets are likely to be taken, since they are probably loops. That means you're better off putting your termination test at the end of the loop, and to account for loops where you tes