From: Frazier, J. J. <Joe...@Pe...> - 2001-09-06 12:40:20
|
> -----Original Message----- > From: $Bill Luebkert [mailto:db...@wg...] > Sent: Wednesday, September 05, 2001 22:47 > To: Frazier, Joe Jr > Cc: per...@li... > Subject: Re: Schwartzian Transform? >=20 >=20 > "Frazier, Joe Jr" wrote: > > I have the above data structure( which will=20 > ultimatly contain > > 6-7 items per array reference and many array elements) and=20 > need to be > > able to sort/reverse sort on any of the reference elements.=20 > I know the > > Schwartzian Transform is the right way to go, but I havent=20 > a clue how to > > start(tried a few things, but no luck). Example: <cut attempt=3D"totallywrong" code=3D"bad" /> > > Please help. Forgive the HTML post, I have to=20 > access my work > > email from home using Outlook web mail access..... > >=20 >=20 > You don't need it here. >=20 > use strict; >=20 > my @rows =3D ( > ['Joe', 'Frazier, Jr.', ''],=20 > ['abracadabra', 'magic word', ''],=20 > ['John', 'First name', ''],=20 > ['ciao', 'greetings', 'five'],=20 > ); > my @result; > =20 > dosort (\@rows, \@result, 1, 'f'); > exit 0; > =20 > sub dosort { # dosort \@sort, \@result, column 0 to=20 > n, 'f'|'r' > my ($sort, $sorted, $col, $dir) =3D @_; >=20 > if ($dir eq 'f') { > @$sorted =3D sort { $a->[$col] cmp $b->[$col] } @$sort; > } else { > @$sorted =3D sort { $b->[$col] cmp $a->[$col] } @$sort; > } >=20 > } >=20 > __END__=20 Thanks Bill, that did EXACTLY what I needed! Here is part of the script I have been working (Win32::GUI::Listview control) in case anyone else wants to look at it: use Win32::GUI; # define GLOBAL sort criteria: my $dir =3D 'f'; my $sortCol; # One thing not here is that I define a property of the lvwJobposts object ($win->lvwJobposts->{Columns}) to hold the number(actually, the last column index) of columns in the list view. ....# create window and controls...... # given a listview control Named lvwJobposts: sub lvwJobposts_ColumnClick{ my $sort =3D shift; # selected Column my @Rows; for(my $x =3D 0; $x < $win->lvwJobposts->Count();$x++){ my @Values; for(my $y =3D 0; $y <=3D $win->lvwJobposts->{Columns}; $y++){ my %data =3D $win->lvwJobposts->ItemInfo($x, $y); push @Values, $data{-text}; # push each row->Column value into array } push @Rows, \@Values; # push each row into @Rows array } if ($sort =3D=3D $sortCol){ # Determine if we are sorting on same column as last time if($dir eq 'f'){ # if so, reverse sort order.... $dir =3D 'b'; }elsif($dir eq 'b'){ $dir =3D 'f'; } =09 }else{ # otherwise, this is a new column and set sort to forward $sortCol =3D $sort; $dir =3D "f"; } my @result; dosort (\@Rows, \@result, $sort, $dir); $win->lvwJobposts->Clear(); # Clears the list view for (my $d =3D 0; $d <=3D $#result;$d++){ Win32::GUI::DoEvents(); # thrown in in case there a a large number of Rows $win->lvwJobposts->InsertItem(-text =3D>$result[$d]); # adds back a row at a time } } sub dosort { # dosort \@sort, \@result, column 0 to n, 'f'|'r' my ($sort, $sorted, $col, $dir) =3D @_; if ($dir eq 'f') { @$sorted =3D sort { $a->[$col] <=3D> $b->[$col] || $a->[$col] cmp $b->[$col] } @$sort; } else { @$sorted =3D sort { $b->[$col] <=3D> $a->[$col] || $b->[$col] cmp $a->[$col] } @$sort; } } >=20 > PS: Done much boxing lately ? :) >=20 Not lately. To busy trying to master Perl( it would help if I had a job where it was what I did) Now, anyone want to give me 1-2 examples of using the Schwartzian Transform and break it down?( I have seen the one linked to from perl.com, but it kind of makes my head hurt. I also searched google, but found that one and a few other links that did not really explain when to use and how it works.) Joe Frazier, Jr Technical Support Engineer PeopleClick 919-645-2916 joe...@pe... =20 |