Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Thanks.#! /usr/bin/perl -w use strict; my @v; $v[0]=via_format(1,2); $v[1]=via_format(1,12); $v[2]=via_format(1,4); $v[3]=via_format(6,12); $v[4]=via_format(1,5); &printV; for (my $swapping = 1; $swapping >= 0; $swapping--) { for (my $j=0; $j < $#v; $j++ ) { if ( (index($v[$j],$v[$j+1]) >= 0) || (length($v[$j+1]) < length($v[$j])) || ($v[$j+1] lt $v[$j] && length($v[$j+1]) <= length($v[$j]) +) ) { @v[$j,$j+1] = @v[$j+1,$j]; $swapping = 1; } } } &printV; sub printV { my $i; print "----------------------\n"; for ($i=0; $i <= $#v; $i++) { print $v[$i] . "\n"; } } sub via_format { my $a = shift; my $b = shift; return join('+', map{sprintf("%02d", $_)} ($a..$b) ); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Funky sorting
by Fletch (Bishop) on Nov 10, 2001 at 04:59 UTC | |
by cacharbe (Curate) on Nov 10, 2001 at 07:41 UTC | |
|
Re: Funky sorting
by blakem (Monsignor) on Nov 10, 2001 at 04:34 UTC | |
by tye (Sage) on Nov 10, 2001 at 04:44 UTC | |
by blakem (Monsignor) on Nov 10, 2001 at 05:03 UTC | |
by Anonymous Monk on Nov 10, 2001 at 05:46 UTC | |
|
Re: Funky sorting
by mitd (Curate) on Nov 10, 2001 at 09:32 UTC | |
|
Re: Funky sorting
by Anonymous Monk on Nov 11, 2001 at 02:42 UTC | |
by cacharbe (Curate) on Nov 11, 2001 at 09:30 UTC |