in reply to my $a outside sort block incompatibility

Would something like this be easier and less (potentially) misleading...?

my $moo = 3; @arr2 = sort { $moo <=> $b } @arr1;

Replies are listed 'Best First'.
Re^2: my $a outside sort block incompatibility
by Anonymous Monk on Feb 21, 2009 at 00:37 UTC
    Thanks for replying. I guess I wasn't clear enough. Actually, the two $a variables are supposed to be unrelated. The "my $a" is hypothetically a reasonably appropriate name chosen for the variable given its meaning, but it happens to conflict with perl's use of global $a.
      I have significant difficulty in accepting that hypothesis.

      $i/$j/(occasionally) $k are sufficiently widely-used and well-known that they are acceptable as loop counters. $x/$y/$z are appropriate for geometric coordinates, again due to long and widespread use.

      Offhand, I can think of no other cases in which a single-character variable name is "reasonably appropriate", regardless of whether it happens to conflict with a magical name built into the language or not.

        Offhand, I can think of no other cases in which a single-character variable name is "reasonably appropriate",

        How about the long standing convention of my( $r, $g, $b );?


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

        $u and $v are also standard for coordinates, as of course is $r (in the company of a $theta).

        And plenty of other things use single-letter variables by convention. If I were implementing a quadratic equation solver, for example, I would consider it obfuscation to name the coefficients anything other than $a, $b, and $c.

        The question should never be "does this variable name meet some arbitrary standard", but rather "will my successor, trying to maintain this code in a few years' time, immediately grasp what this variable is for". If the answer is "yes" (and can be justified!), then any name is potentially appropriate, regardless of length.