in reply to Specifying main:: scope

I am not sure exactly what you're asking. You wrote that $a and $b live in %main::, but in a sort routine, they actually are package globals in whatever package you currently happen to be in. Now, if you're stating that the variables that $a and $b are comparing live in %main:, that's irrelevant because they are aliasing the original variables.

If you want to use &directories_first as a sort routine, but it might be in a different package, you can use prototypes:

our %df_keys; sub directories_first ($$) { $df_keys{$_[0]} ||= df_key($_[0]); $df_keys{$_[1]} ||= df_key($_[1]); return ( $df_keys{$_[0]} cmp $df_keys{$_[1]} ); } # somewhere else in the galaxy: my @new_array = sort Some::Package::directories_first @old_array;

See perldoc -f sort for details. I hope this helps because I really didn't understand your question :)

Cheers,
Ovid

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.