Hello everyone, I was reading about sort in the camel (3rd ed., p. 793) and I found that sorting subroutines must be placed in the same package as they are called from since $a and $b are package globals. Therefore, sorting functions cannot be "modulized" without help. The camel suggests two workarounds: qualifying $a and $b with the package name of the caller, and passing $a and $b as arguments (which also requires prototyping the sorting function and declaring $a and $b as lexicals).
I was able to get the second method to work, but not the first. Could someone please explain (and provide an example of) how the package name of the calling function can be used to qualify $a and $b, as suggested in the camel? I tried playing around with the *{foo}{PACKAGE} and *{foo}{NAME} notation, but without success. On a related note, is one of these two methods preferred over the other? Here are the tests I've tried. Both give the expected output: unsorted: 1 9 5 10 2 sorted: 1 2 5 9 10 ** sort routine in same package ** SORTTEST.PL: use strict; use warnings; my @nums = qw( 1 9 5 10 2 ); print "unsorted: @nums\n"; @nums = sort numerically @nums; print "sorted: @nums\n"; sub numerically { $a <=> $b; } ** sort routine in a separate package ** SORTTEST.PL: use strict; use warnings; use Sort_Numerically; my @nums = qw( 1 9 5 10 2 ); print "unsorted: @nums\n"; @nums = sort numerically @nums; print "sorted: @nums\n"; SORT_NUMERICALLY.PM: package Sort_Numerically; use strict; use warnings; use Exporter; our @ISA = ( "Exporter" ); our @EXPORT = ( "numerically" ); sub numerically ($$) { my ( $a, $b ) = @_; $a <=> $b; } Thanks in advance, Bob Robert Freimuth, PhD Post-Doctoral Fellow Washington University School of Medicine Department of Internal Medicine Division of Molecular Oncology -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]