in reply to Re: Re: package globals and sort()
in thread package globals and sort()
Just do the actual sort in the MyOrder Package as shown. Note as we pass list references we pass 4 bytes in and 4 bytes out of the MyOrder package.
package MyOrder; my %order = ( ); sub SortCriteria { if ( exists $order{$a} and exists $order{$b} ) { return $order{$a} <=> $order{$b} } elsif ( exists $order{$a} ) { return 1 } elsif ( exists $order{$b} ) { return -1 } else { return $a cmp $b } } sub SortMyWay { my $list_ref = shift; return [sort SortCriteria @$list_ref]; } package main; use strict; my @foo = qw( j a p h , ); my $bar = MyOrder::SortMyWay(\@foo); my @bar = @$bar; print "@bar";
cheers
tachyon
s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Re: package globals and sort()
by Anonymous Monk on Apr 19, 2002 at 01:48 UTC | |
by tachyon (Chancellor) on Apr 19, 2002 at 02:09 UTC |