On 9/12/07, Peter Scott <[EMAIL PROTECTED]> wrote:
> If you do
>
> my $a = 6.023E23; # Avagadro's number
> # Many lines of chemistry code elided
> @elements = sort { $atomic_wt{$a} <=> $atomic_wt{$b} } @elements;
>
> you get
>
> Can't use "my $a" in sort comparison
>
> which is going to annoy someone who then has to change all the
> references to Avagadro's number.
That would be annoying. But why would they change dozens of $a's to
$avogadro instead of simply fixing the sort to use the right package
variable, as perldiag suggests?
@elements = sort { $atomic_wt{$pkg::a} <=> $atomic_wt{$pkg::b} } @elements;
There's no doubt that $a and $b were poor choices for sort. It's too
bad that Larry didn't choose other names, or capitalize them, or
something. I rarely use single-letter names for long spans of code,
but if I did, I'd capitalize the name because $A stands out and makes
a better name Avogadro. And you can use it during a sort().
--Tom Phoenix
Stonehenge Perl Training
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/