Thanks Bruce Van Allen and Ken Williams!

I've just implemented Bruce's suggestion:

    sub naturalorder {
    # A subroutine that sorts like the Macintosh Natural Order extension.
    # Created by Vic Norton, 26 Nov 2000.
    # Modified to work in an external package on 27 Jan 2001;
    # Thanks to Bruce Van Allen <[EMAIL PROTECTED]>.

    # Bruce Van Allen's modification
        my ($pkg) = caller;
        no strict 'refs';
        my $a = ${$pkg.'::a'};
        my $b = ${$pkg.'::b'};

    # Norton's original routine continues from here
        my $u = lc($a);
        my $v = lc($b);
        ...
    }

This solution works perfectly!

Regards,

Vic

At 10:01 PM -0800 1/26/01, Bruce Van Allen wrote:
>At 2:22 PM -0500 1/26/01, Vic Norton wrote:
>>How do you package a sorting subroutine for use with sort? That's 
>>what I don't understand.
>
>[snip]
>
>>I assume that I am losing $a and $b when my subroutine resides in the
>>external package VTN::Utilities, but I don't know what to do about it.
>
>The global variables $a and $b are temporarily set in the package 
>where the sort routine was compiled. So, if your sort subroutine is 
>defined in an external package, to access the sort variables you'll 
>need to make $a and $b properly qualified over there.
>
>...



Reply via email to