donfreenut has asked for the wisdom of the Perl Monks concerning the following question:
---if($sort_field eq 'createtime') { for $node (sort { ($date, $time) = split / /, $nodes{$a}{createtime}; ($year, $month, $day) = split /-/, $date; ($hour, $min, $sec) = split /:/, $time; $create_timeA = timelocal($sec,$min,$hour,$day,$month,$year); ($date, $time) = split / /, $nodes{$b}{createtime}; ($year, $month, $day) = split /-/, $date; ($hour, $min, $sec) = split /:/, $time; $create_timeB = timelocal($sec,$min,$hour,$day,$month,$year); if($sort_order eq 'ASC') { return $create_timeA <=> $create_timeB; } else { return $create_timeB <=> $create_timeA; } } keys %nodes) { print "$node: $nodes{$node}{$sort_field}\n"; } } else { whatever; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Shrink this sort subroutine
by merlyn (Sage) on Apr 24, 2001 at 22:32 UTC | |
by donfreenut (Sexton) on Apr 24, 2001 at 22:37 UTC | |
|
Re: Shrink this sort subroutine
by tadman (Prior) on Apr 24, 2001 at 23:09 UTC | |
by $code or die (Deacon) on Apr 25, 2001 at 01:19 UTC | |
|
Re: Shrink this sort subroutine
by suaveant (Parson) on Apr 24, 2001 at 22:30 UTC | |
by donfreenut (Sexton) on Apr 24, 2001 at 22:33 UTC | |
by suaveant (Parson) on Apr 24, 2001 at 22:36 UTC | |
|
Re: Shrink this sort subroutine
by suaveant (Parson) on Apr 24, 2001 at 22:35 UTC |