Jorge said:
I'm running ActiveState perl 5.8.8 on XP
While working on my dog racing program, I build an array containing
these strings which are numerically indexed 1 thru 8 by the last
column.
31.43 32 1005.89 Figs Domino 1
31.62 17 537.57 Boc's Skater 2
31.85 18 573.34 Reward Crystal 3
31.54 27 851.47 Db Miss Buxley 4
31.78 13 413.17 Ucme Lola 5
31.96 12 383.46 Bayou Jasmine 6
31.62 14 442.62 Y's Flirt 7
31.46 30 943.88 Sheriff Wade 8
I pass the array to my schwartzian transform sub routine using this
call ...
my @sorted_array = &SchwartzianTransform(' ', ['1n', -1], @array);
with expectations of it returning an array that is sorted on the
numerical 1st column (2-place floats) but it always returns the
original array.
For me it returns the sorted array. Show a complete, runnable
program that shows the behavior you are seeing.
Anno
Here is the program which requires a dedicated directory named
c:\dogs\tonight which contains the data file (at the end of the post --
truncated to save bandwidth).
snip<------ program starts here ------>snip
#!perl -lw
use warnings;
use strict;
use File:

ath;
&createIndividualDogsFiles("c:\\dogs\\tonight");
sub createIndividualDogsFiles{
my(@filesArr, $filesArr, $dir, $path, $total, $totalCnt, $avg);
my($phx, $day, $mon, $dat, $yr, $matEve, $Race, $raceNum, $Grade);
my($gradeLet, $Dist, $distNum, $race, $numOfRaces, $racesAdded, $ans);
my($vaultFile, $raceArr, $dogName, $todaysPostNum, $finalTime,
$field1);
my $flag = 0;
my @resultsArr = ();
my $weight;
my $pp;
my($junk1, $junk2, $junk3);
my(@array, $array, $string, @sorted_array, $line);
$dir = shift;
unless (opendir(DIR, $dir)) {
warn "Can't open $dir\n";
closedir(DIR);
return;
}
foreach (readdir(DIR)) {
next if $_ eq '.' || $_ eq '..';
$path = "$dir\\$_";
if (-d $path) { # a directory
&createIndividualDogsFiles($path);
} elsif ( -f _) { # a plain file
open(IN, "$path") || die "Can't open $path for read: $!";
while(<IN>){
next if /^\s*$/ || /______/ || /======/ || / Owner / || / Trn /;
s/\s+\Z//;
if($_ =~ /Rosnet\,/ && $_ =~ /Race [0-9]/){
($junk1, $junk2, $junk3, $phx, $day, $mon, $dat, $yr, $matEve,
$Race,
$raceNum, $Grade, $gradeLet, $Dist, $distNum) = split(' ', $_,
14);
$race = "$Race"."_"."$raceNum"."_"."$gradeLet";
print "\n$race\n================";
}
elsif($_ !~ /Rosnet\,/ && $_ =~ /Race [0-9]/){
($phx, $day, $mon, $dat, $yr, $matEve, $Race, $raceNum,
$Grade, $gradeLet, $Dist, $distNum) = split(' ', $_, 12);
$race = "$Race"."_"."$raceNum"."_"."$gradeLet";
print "\n$race\n================";
}
elsif($_ =~ /Ken / && $_ =~ / Grade /){
$total = 0; $totalCnt = 0; $avg = 0;
$todaysPostNum = substr($_, 0, 1);
$dogName = substr($_, 2, 18);
$vaultFile = "c:\\dogs\\vault\\$dogName";
open(VDOG, "$vaultFile") || die "Can't open $vaultFile for
reading: $!";
while(<VDOG>){
my @stats = split(' ', $_);
my $fraction = $stats[1];
$total += $fraction;
++$totalCnt;
}
close(VDOG);
if($totalCnt > 0){
$avg = $total / $totalCnt;
$string = sprintf("%.2f %-3s%-8s%-20s%-2s", $avg, $totalCnt,
$total, $dogName, $todaysPostNum);
push(@array, $string);
}else{
$string = "$todaysPostNum $dogName --- No Data ---";
push(@array, $string);
}
}
@sorted_array = &SchwartzianTransform(' ', ['1n', -1], @array);
foreach $line(@sorted_array){
print "$line";
}
@array = ();
@sorted_array = ();
}
close(IN);
}
}
closedir(DIR);
}
#================================
# SUBROUTINE SchwartzianTransform
#================================
sub SchwartzianTransform{
my ($sep, $cols);
if (ref $_[0]) {
$sep = '\\s+'
} else {
$sep = shift;
}
unless (ref($cols = shift) eq 'ARRAY') {
die "fieldsort columns must be in anon array";
}
my (@sortcode, @col);
my $col = 1;
for (@$cols) {
my ($a, $b) = /^-/ ? qw(b a) : qw(a b);
my $op = /n$/ ? '<=>' : 'cmp';
push @col, (/(\d+)/)[0] - 1;
push @sortcode, "\$${a}->[$col] $op \$${b}->[$col]";
$col++;
}
my $sortfunc = eval "sub { " . join (" or ", @sortcode) . " } ";
my $splitfunc = eval 'sub { (split /$sep/o, $_)[@col] } ';
return
map $_->[0],
sort { $sortfunc->() }
map [$_, $splitfunc->($_)],
@_;
}
__END__
snip<----- data file ------>snip
Rosnet,Inc - Greyhound RacingPhoenix Tuesday Sep
05 2006 Evening Race 1 Grade D Dist 550
1 Figs Domino Ken Olsker Kennel Corp PH 44 5 8 4
5 Hi Grade - A Lo Grade - D
Trn Tim Olsker PH 9 3 1 0
2 Best Time 30.85
Black M 6/5/2004 Courageous Nicky Figs Cher Owner Dick Figurilli
PH09-01-06E 03 550 F 31.07 77½ 5 2 2 3 3 5 31.44 05.30 D
Bumped 1st Turn GecMartin Gablicious Chsm'sIndy 8
PH08-27-06E 13 550 F 31.58 77 5 7 4 4 4 8 32.13 07.80 D
Evenly, Inside Rd'sQuenAn GlsRustler Boc'sAttid 8
PH08-21-06E 13 550 F 31.82 76½ 1 1 1 2 1 2 2 1½ 31.92 05.30 D
Outfinished, Inside WntsAndNed KmaDiesel RwardFrsty 8
PH08-15-06E 03 550 F 31.16 77 3 6 4 5 6 10 31.85 27.60 C
Wide In Stretches KayFrbidng UsGoldenRl PatCPayabl 8
PH08-09-06E 11 550 S 31.75 78 3 4 6 6 6 14 32.77 21.50 C
Bumped 1st Turn CstarDesrt He'sOnThRn Flea'sCuti 8
PH08-04-06E 15 550 F 30.81 77 7 5 4 4 6 14 31.79 12.30 C
Offstride Far Turn StatUSDarD Bc'sLilNck AngelcBaty 7
_________________________________________________________________________________________________________________________
2 Boc's Skater Ken Bret Pachello PH 18 1 1 2
5 Hi Grade - B Lo Grade - D
Trn Michael Robinette PH 0 0 0 0
0 Best Time 31.05
Brindle M 3/12/2003 Trojan Cruze Contradiction Owner Brad Boeckenstedt
PH09-01-06E 01 550 F 31.19 75½ 6 2 2 4 8 16 32.35 12.40 D
Bumped Homestretch Absolm KmaKatnamo TvDamndbck 8
PH08-28-06S 07 550 F 31.86 75½ 7 4 2 3 5 12 32.74 ----- SD
Faded Far Turn Rlm'sBrwsr Boc'sMvnOn CldwaterIr 6
PH08-24-06S 08 550 F 31.6 77 1 2 1 hd 1 ½ 3 5 31.96 ----- SD
Outfinished, Inside Kaynta DjaysBlstO Boc'sBluBy 6
PH06-26-06E 01 550 F 31.37 74 4 6 5 5 5 8 31.91 11.50 D
Never Prominent Rj'sAntiEm BcAllstar MaraTheSam 7
PH06-18-06E 09 550 F 31 74½ 3 1 5 7 7 14 32.03 19.30 D
Early Threat, Faded LowFlynRck RagingSurf FigsDomino 8
PH06-11-06E 03 550 F 30.77 74½ 3 2 5 7 8 28 32.74 10.30 D
Collided 1st Turn Rd'sUndo UsLateShow TuffyTitan 8
_________________________________________________________________________________________________________________________
3 Reward Crystal Ken Gloria Dorsey PH 20 4 1 1
1 Hi Grade - C Lo Grade - M
Trn Patrick Phillips 0 0 0 0
0 Best Time 30.94
Dark Brindle F 9/13/2004 Wigwam Hoss Hkw Pongacrystal Owner Dr. Carl
E. Ward
PH08-31-06E 09 550 F 31.06 59½ 4 4 5 7 8 10 31.78 10.20 D
Steady Fade KrazyAsKat AmfAdroit JupiterTym 8
PH08-27-06E 07 550 F 31.65 59 2 3 2 4 6 10 32.34 04.90 D
Steady Fade ThinkMore UcmeKimmi Auster 8
PH08-21-06E 03 550 F 31.66 60 7 3 2 6 7 11 32.44 04.40 D
Crowded Backstr & Fa Wayn'sBbyd KaycarDshr FgsSmallBs 8
PH08-17-06E 01 550 F 31.21 60 6 2 2 2 2 5½ 31.59 12.90 D
Chased Winner, Insid GpherChcks BcGeeHoney KmWhodoVoo 8
PH08-12-06E 13 550 F 31.15 59½ 6 5 5 6 8 12 32.04 10.90 C
Never A Threat GlsRedalrt RsSammy HeyKnocker 8
PH08-06-06E 15 550 S 31.54 59 8 2 2 2 4 9 32.15 22.70 C
Weakened Hmstrch, In CldwterThe FigsMona GrysSnKing 8
_________________________________________________________________________________________________________________________
4 Db Miss Buxley Ken Olsker Kennel Corp PH 35 1 8 5
9 Hi Grade - C Lo Grade - J
Trn Tim Olsker PH 60 5 8 5
7 Best Time 31.13
White Black Bd. F 7/6/2003 Craigie Glen Db Cinema Owner Duran Bros.
PH09-01-06E 17 550 F 31.38 54½ 1 1 5 4 4 10 32.11 05.20 C
Bumped 1st Turn FlthyMcNst DafodlDbrh SavvyLouis 8
PH08-27-06E 11 550 F 31.29 54 8 8 8 8 8 17 32.49 11.60 C
Bumped 1st Turn Kane'sRchl Brilntcrnr Rlm'sLardo 8
PH08-23-06E 11 550 F 31.62 54½ 6 2 2 3 4 6 32.06 05.30 C
Outfinished, Inside NatashaLyn I'llTwThen DafodlDbrh 8
PH08-19-06E 17 550 S 32.08 54 3 7 4 5 7 11 32.92 08.10 C
Some Fade CruzenWili Brilntcrnr NatashaLyn 8
PH08-14-06E 02 550 F 31.56 55½ 2 1 2 2 2 ½ 31.61 07.00 C
Almost Up, Inside RagingSurf BellaAwacs Brilntcrnr 8
PH08-09-06E 09 550 S 31.98 55 2 2 3 6 8 10 32.73 04.50 C
Early Threat, Faded BestBetsy Rd'sNabsco RagingSurf 8
_________________________________________________________________________________________________________________________
5 Ucme Lola Ken Fidel Or Silvia SambadePH 24 1 4 3
4 Hi Grade - C Lo Grade - J
Trn Willie Davis 0 0 0 0
0 Best Time 31.05
Red F 2/19/2004 Ww Night Rider Passion Plan Owner Sherry De Witt Or
Shelly Rangel
PH08-31-06E 05 550 F 31.4 61½ 2 6 5 5 6 13 32.37 04.50 D
Offstr 1st Tn - Blck StatUSJyze CldwatrKck HindSight 8
PH08-25-06E 01 550 F 31.45 61½ 3 7 8 7 8 19 32.84 05.90 D
Bumped 1st & Homestr OddMonica AcMyPrsasn IrskaRedMg 8
PH08-20-06E 09 550 F 31.6 60 5 7 4 3 2 4 31.89 *03.50 D
Offstride Early Beemr Maybemybnt Twistedmnt 8
PH08-15-06E 09 550 F 30.75 60 5 5 3 2 2 10 31.52 06.20 D
Next Best, Midtrack Cherryprsp Boc'sSnoke MoonMtCrky 8
PH08-09-06E 01 550 S 31.42 60 7 4 3 2 2 4½ 31.73 14.00 D
Followed The Pace, M WhiskeyWhs CajunVal SweetAzArz 7
PH08-05-06E 07 550 S 32.26 60½ 4 5 5 3 4 12 33.14 06.50 D
Bumped 1st Turn FgsArmstrn NotAzChocl Hj'sTyler 8
_________________________________________________________________________________________________________________________
6 Bayou Jasmine Ken George Fune PH 18 1 0 2
5 Hi Grade - D Lo Grade - J
Trn Dorothy Fune 0 0 0 0
0 Best Time 31.62
Brindle F 4/3/2004 Oshkosh Slammer Mesa Greatone Owner Van Strother
PH09-01-06E 07 550 F 31.25 58 5 8 5 5 5 7 31.76 15.50 D
Bumped 1st Turn Auster SherifWade FgsSmallBs 8
PH08-28-06E 11 550 F 31.36 57 2 7 8 8 8 13 32.32 42.90 D
Bumped 1st Turn UsValeyFrg SltaryChrg See URound 8
PH08-24-06E 07 550 F 30.9 57½ 1 7 8 7 7 20 32.35 07.80 D
Always Back GecHottie UsValeyFrg DutchLilAn 8
PH08-18-06E 03 550 F 31.26 58 5 8 6 6 4 9 31.88 05.30 D
Sht Off Erly - Frcd CstarTaran FgsDarkKal UcmeJoe 8
PH08-12-06E 05 550 F 31.62 57½ 5 6 4 2 1 1½ 31.62 15.40 J
Drove To Win, Midtra ChicagMcky UsLandRovr BcBillyBoy 8
PH08-03-06E 05 550 F 31.21 57 7 6 5 5 3 8½ 31.81 21.10 J
Bumped 1st Turn SpicyDream BubleGmFev KayCeeSasn 7
_________________________________________________________________________________________________________________________
7 Y's Flirt Ken Fidel Or Silvia SambadePH 18 3 1 2
2 Hi Grade - C Lo Grade - M
Trn Willie Davis 0 0 0 0
0 Best Time 31.03
Black M 7/4/2004 Oshkosh Slammer Tm's Merry Pace Owner Silvia Sambade
PH08-26-06E 07 550 F 31.81 74 6 5 6 6 6 10 32.51 08.70 D
Bumped 1st Turn Rd'sVictor Fla'sHiway IrskaMyrtl 8
PH08-17-06E 01 550 F 31.21 74 1 6 5 5 7 11 31.99 05.30 D
Offstride 1st & Far GpherChcks RwardCryst BcGeeHoney 8
PH08-11-06E 17 550 M 31.17 75 6 4 5 5 7 22 32.75 09.10 C
Crowded Far Turn ClSpeedie I'llTwThen Rd'sKates 7
PH08-07-06E 14 550 S 31.47 73 6 6 4 4 6 13 32.43 12.70 C
Late Fade SlitaryAsh GecHenry RewrdRedGr 7
PH08-03-06E 09 550 F 31.1 73½ 3 6 7 8 8 16 32.24 14.60 C
Bumped 1st Turn DtchDaniel RagingSurf RsSammy 8
PH07-29-06E 17 550 F 30.5 73½ 1 5 5 6 4 16 31.62 03.50 C
Varied Little, Insid AndrwsPstc UssVentura FigsIou 8
_________________________________________________________________________________________________________________________
8 Sheriff Wade Ken Lonnie Boyle PH 34 4 6 1
7 Hi Grade - B Lo Grade - D
Trn Jamie Boyle PH 18 1 3 4
5 Best Time 30.79
Black M 3/13/2004 Scorcher's Ace Dawn's Earlylite Owner Howard L.
Marshall
PH09-01-06E 07 550 F 31.25 76½ 2 2 2 2 2 2 31.38 07.70 D
Followed The Pace, I Auster FgsSmallBs UcmeKimmi 8
PH08-27-06E 01 550 F 31.73 77½ 7 8 8 8 8 10 32.42 21.50 D
Offstride 1st Turn LitlLisaLo HindSight IvansImage 8
PH08-22-06E 09 550 F 31.42 75 4 2 5 5 8 14 32.44 08.10 D
Dropped Back Early BcGeeHoney MoonMtBomr KmaKatnamo 8
PH08-17-06S 06 550 F 31.27 76½ 6 2 4 4 4 10 31.99 ----- SD
Slight Factor, Insid GecMartin Vl ColdwterDn 7
PH07-30-06E 13 550 F 30.99 76½ 1 3 5 5 5 7½ 31.52 03.40 D
Never Prominent FigsMona Insider'sG QalityChic 8
PH07-24-06E 01 550 F 31.02 77 4 6 5 4 4 6 31.45 03.40 D
Bumped At Break & Ea FgsconchCr CldwatrKck ImaKtyDdgr 8
_________________________________________________________________________________________________________________________
=========================================================================================================================