vitaly has asked for the wisdom of the Perl Monks concerning the following question:
my @xx = ( 'dfb|cy|nmju', 'dfb|my|jhiho', 'aaa|zz|gggg' ); my @sorted_xx = sort sorter @xx; print Dumper \@xx; print Dumper \@sorted_xx; sub sorter { my @arr_a = split /\|/, $a; my @arr_b = split /\|/, $b; while ( @arr_a ) { my $sa = shift @arr_a; my $sb = shift @arr_b; my $comparison = ( $sa cmp $sb ); return $comparison if $comparison; } return 0; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Pass additional params into sub which create sorting rules
by moritz (Cardinal) on Dec 02, 2007 at 17:26 UTC | |
|
Re: Pass additional params into sub which create sorting rules
by shmem (Chancellor) on Dec 02, 2007 at 17:29 UTC | |
|
Re: Pass additional params into sub which create sorting rules
by kyle (Abbot) on Dec 02, 2007 at 21:32 UTC | |
|
Re: Pass additional params into sub which create sorting rules
by sgifford (Prior) on Dec 04, 2007 at 06:35 UTC |