Eh? You will need to post code because it has nothing to do with $a and $b being in one package or another. You can see this example works fine.
You can declare a my $a or my $b in package main but not in package Sort as these vars need to be package globals there for sort() to work.
package Sort; # my($a,$b); # <<-- can't do that in this package sub my_num_sort { my $list_ref = shift; # return as a list ref for efficiency return [sort { $b <=> $a } @$list_ref]; } package main; # my($a,$b); # <<-- you can do this in this package (no sorts) my @list = ( 10, 42, 66, 1, 81, 32 ); # pass and return as a list ref for efficiency my $sorted = Sort::my_num_sort(\@list); print "$_ " for @$sorted;
cheers
tachyon
s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print
In reply to Re: package globals and sort()
by tachyon
in thread package globals and sort()
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |