How do you package a sorting subroutine for use with sort? That's 
what I don't understand.

For example I have written a "naturalorder" subroutine to sort 
strings like the "natural order" system extension.

The script

    my @before = ( 'e 213', 'e21a', 'e  0212' );
    my @after = sort naturalorder @before;
    print "@after\n";

Prints out

    e21a e  0212 e 213

when the subroutine naturalorder is compiled on the same page. This 
is the correct "natural order".

However, when I try to package the naturalorder subroutine and access it via

    use VTN::Utilities qw(naturalorder);

then my script outputs the original order:

    e 213 e21a e  0212


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. Can someone tell me how write a packaged sorting subroutine so 
that it works with sort?

Regards,

Vic

Reply via email to