hi. i'm trying to sort a win32::gui listview when a column header is clicked and it works wonderfully for columns 1,2 and 3, but column 4 it just won't sort properly (yes column 4 are numbers). i've been over it like a million times and i just can't see where it's going wrong. any ideas? (code below)

sub ListView_ColumnClick { $totalcols = 6; #5 and 6 are hidden my $column = shift; $column=$column+1; if ($lastcolumn == $column) { $sortorder = 1 - $sortorder; } else { $sortorder = 0; } %data=(); $rows=$ListView->Count(); for $i(0..$rows-1) { $row=""; my %result=$ListView->GetItem($i,0); $image=$result{-image}; for $j(0..$totalcols-1) { my %result=$ListView->GetItem($i,$j); $text=$result{-text}; $row.=",$text"; } $data{$i}="$image$row"; } my %sortcol = NewList($column, %data); SortListItem(\%data,\%sortcol,$column); if ($sortorder) { print "Sorted descending by Column $column\n"; } else { print "Sorted ascending by Column $column\n"; } return; } sub SortListItem { my ($data,$sortcol,$column) = @_; my $check; my %data = %$data; my %sortcol = %$sortcol; $check = "$_" foreach (values %sortcol); $ListView->Clear(); ## clear the ListView window $index = 0; if ($sortorder == 0) { ## this is sorting in ascending order if (($column == 1) or ($column == 4)) { foreach (sort{(substr($sortcol{$a},0,index($sortcol{$a}," "))) +<=> (substr($sortcol{$b},0,index($sortcol{$b}," "))) } keys %sortcol) + { my @newdata = split/,/,$data{$_}; InsertListItem(@newdata); } } else { foreach (sort { uc($sortcol{$a}) cmp uc($sortcol{$b})} keys %so +rtcol) { my @newdata = split/,/,$data{$_}; InsertListItem(@newdata); } } } else { ## this is sorting in descending order if (($column == 1) or ($column == 4)) { foreach (sort {(substr($sortcol{$b},0,index($sortcol{$b}," "))) + <=> (substr($sortcol{$a},0,index($sortcol{$a}," "))) } keys %sortcol +) { my @newdata = split/,/,$data{$_}; InsertListItem(@newdata); } } else { foreach (sort { uc($sortcol{$b}) cmp uc($sortcol{$a})} keys %so +rtcol) { my @newdata = split/,/,$data{$_}; InsertListItem(@newdata); } } } return; } sub NewList { my ($column,%sortcol) = @_; my $sortthis; foreach (keys %sortcol) { my @info = split /,/, $sortcol{$_}; $sortthis = $info[$column]; $sortcol{$_} = "$sortthis"; } return(%sortcol); } sub InsertListItem { my(@info) = @_; $Window->ListView->InsertItem( -text => [@info[1],@info[2],@info[3],@info[4],@info +[5],@info[6]], ); }

In reply to sorting a listview by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.