in reply to package globals and sort()
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: package globals and sort()
by Anonymous Monk on Apr 19, 2002 at 00:49 UTC | |
by tachyon (Chancellor) on Apr 19, 2002 at 01:10 UTC | |
by Anonymous Monk on Apr 19, 2002 at 01:48 UTC | |
by tachyon (Chancellor) on Apr 19, 2002 at 02:09 UTC |