in reply to sort routines crossing package lines

$a and $b are not always forced into package main (the way punctuation vars are), and are not magic. But they are localized and aliased to the elements being sorted. The localization temporarily removes the imported ones when you import the scalars rather than the globs. When the globs are imported, the localization replaces what's in the scalar slot of the glob, so it affects the exporting package's "copy".

You can see the same effect here:

$ perl -we'$Foo::a = 2; *a = \$Foo::a; for $a (4) { print $a, $Foo::a +}' 42 $ perl -we'$Foo::a = 2; *a = \*Foo::a; for $a (4) { print $a, $Foo::a +}' 44
Update: meant to say, the above is consistent whether either or both var names are a or b or not.

Replies are listed 'Best First'.
Re^2: sort routines crossing package lines
by DrWhy (Chaplain) on Nov 26, 2004 at 15:01 UTC
    Eureka! I do believe ysth's got it.

    /me wishes he could up vote more than once...

    --DrWhy

    "If God had meant for us to think for ourselves he would have given us brains. Oh, wait..."