> -----Original Message----- > From: $Bill Luebkert [mailto:[EMAIL PROTECTED] > Sent: Wednesday, September 05, 2001 22:47 > To: Frazier, Joe Jr > Cc: [EMAIL PROTECTED] > Subject: Re: Schwartzian Transform? > > > "Frazier, Joe Jr" wrote:
> > I have the above data structure( which will > ultimatly contain > > 6-7 items per array reference and many array elements) and > need to be > > able to sort/reverse sort on any of the reference elements. > I know the > > Schwartzian Transform is the right way to go, but I havent > a clue how to > > start(tried a few things, but no luck). Example: <cut attempt="totallywrong" code="bad" /> > > Please help. Forgive the HTML post, I have to > access my work > > email from home using Outlook web mail access..... > > > > You don't need it here. > > use strict; > > my @rows = ( > ['Joe', 'Frazier, Jr.', ''], > ['abracadabra', 'magic word', ''], > ['John', 'First name', ''], > ['ciao', 'greetings', 'five'], > ); > my @result; > > dosort ([EMAIL PROTECTED], [EMAIL PROTECTED], 1, 'f'); > exit 0; > > sub dosort { # dosort [EMAIL PROTECTED], [EMAIL PROTECTED], column 0 > to > n, 'f'|'r' > my ($sort, $sorted, $col, $dir) = @_; > > if ($dir eq 'f') { > @$sorted = sort { $a->[$col] cmp $b->[$col] } @$sort; > } else { > @$sorted = sort { $b->[$col] cmp $a->[$col] } @$sort; > } > > } > > __END__ 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 = '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 = shift; # selected Column my @Rows; for(my $x = 0; $x < $win->lvwJobposts->Count();$x++){ my @Values; for(my $y = 0; $y <= $win->lvwJobposts->{Columns}; $y++){ my %data = $win->lvwJobposts->ItemInfo($x, $y); push @Values, $data{-text}; # push each row->Column value into array } push @Rows, [EMAIL PROTECTED]; # push each row into @Rows array } if ($sort == $sortCol){ # Determine if we are sorting on same column as last time if($dir eq 'f'){ # if so, reverse sort order.... $dir = 'b'; }elsif($dir eq 'b'){ $dir = 'f'; } }else{ # otherwise, this is a new column and set sort to forward $sortCol = $sort; $dir = "f"; } my @result; dosort ([EMAIL PROTECTED], [EMAIL PROTECTED], $sort, $dir); $win->lvwJobposts->Clear(); # Clears the list view for (my $d = 0; $d <= $#result;$d++){ Win32::GUI::DoEvents(); # thrown in in case there a a large number of Rows $win->lvwJobposts->InsertItem(-text =>$result[$d]); # adds back a row at a time } } sub dosort { # dosort [EMAIL PROTECTED], [EMAIL PROTECTED], column 0 to n, 'f'|'r' my ($sort, $sorted, $col, $dir) = @_; if ($dir eq 'f') { @$sorted = sort { $a->[$col] <=> $b->[$col] || $a->[$col] cmp $b->[$col] } @$sort; } else { @$sorted = sort { $b->[$col] <=> $a->[$col] || $b->[$col] cmp $a->[$col] } @$sort; } } > > PS: Done much boxing lately ? :) > 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 [EMAIL PROTECTED]