Re: sorting data - hash vs. list



On Sun, 11 Sep 2005 18:38:06 -0400, "Matt Garrish" <matthew.garrish@xxxxxxxxxxxx> wrote:

>
><Fred@xxxxxxxx> wrote in message
>news:qf79i19v7kqklccnr86pqr56ck5rc6loio@xxxxxxxxxx
>>
>> I have posted here before and been flamed to death, so I guess I'm ready
>> if it happens again. OTH -- I'd be
>> interested in any helpful critisims on my file delete sub. Plus the main
>> question on how to sort that dang file.
>> Thanks,
>>
>
>I can imagine you get flamed, considering your post (adding the isbn of the
>book is called overkill). Anyway, I'm not one to read through reams of other
>people's code to nitpick, so I'll only suggest that you google on the term
>"Schwartzian Transform". The results should explain how trivial the task of
>sorting any data structure with perl can be. For example:
>
>#### Code
>
>use strict;
>use warnings;
>use Time::Local;
>
>my @data;
>
>while (my $line = <DATA>) {
> my @parts = split(/\|/, $line);
> my $date = timelocal(1, 1, 1, split('/', $parts[9]));
> unshift @parts, $date;
> push @data, \@parts;
>}
>
>foreach my $aref (sort { $a->[0] <=> $b->[0] } @data) {
> print join('|', @{ $aref }[1..$#{$aref}]);
>}
>
>__DATA__
>|C|170|901|2|0000000000008|4|000008|5|09/05/05|6|
>|C|170|901|2|0000000000003|4|000008|5|09/06/06|6|
>|C|170|901|2|0000000000001|4|000008|5|09/05/06|6|
>|C|170|901|2|0000000000028|4|000008|5|09/06/05|6|
>
>
>
>
>#### Outputs
>
>|C|170|901|2|0000000000008|4|000008|5|09/05/05|6|
>|C|170|901|2|0000000000028|4|000008|5|09/06/05|6|
>|C|170|901|2|0000000000001|4|000008|5|09/05/06|6|
>|C|170|901|2|0000000000003|4|000008|5|09/06/06|6|
>


Thank you for the example. I was able to work out a solution. It was like I could not see the forest for the trees. Of course, prepend the epoch sconds to the front of the list and sort the zero subscript.
Thank you again,

Fred
.



Relevant Pages

  • Sorting on HoHoH
    ... To access the keys to the hash reference under 'fingers' ordered by the interior number I have made this construct: ... The second sort exploits the fact that the numbers will never be greater than 5, so a default sort will do the same thing as a numeric sort. ... However, I am curious as to how this would be accomplished the "proper" way; that is, by numerically sorting the keys of the anonymous hash referenced by 'finger'. ... Also, if this is a totally ridiculous way of doing things (like, "you're better off with THIS kind of data structure", etc.), you can tell me that, too. ...
    (perl.beginners)
  • Re: COBOL "non-myth" confirmed - Index and subscripts (MF on Windows)
    ... Once you've decided on the data structure, and the general approach to the problem, tiny code level decisions are not going to affect the speed much. ... of a loop that don't need to be in the loop? ... the costs and benefits of a CoBOL sort vs. an external sort? ... There are exceptions to every rule, of course, and such a tiny issue may turn out to be important in some very specialized instance, but in the normal turn of things, micro-level coding is a waste of effort. ...
    (comp.lang.cobol)
  • Re: sorting data - hash vs. list
    ... > I have posted here before and been flamed to death, ... OTH -- I'd be ... > question on how to sort that dang file. ... sorting any data structure with perl can be. ...
    (comp.lang.perl.misc)
  • Re: python 3s adoption
    ... impossible to sort your data structure. ... cannot compare sets using cmp() ... turns out to be disastrous for execution efficiency (unlike the built-in ...
    (comp.lang.python)
  • Re: Data structure
    ... > I'm searching for a data structure which manages sets of integers. ... > The data structure must only support the following 3 operations: ... because the following sort is not ... Bear in mind that Odoes not mean constant time, ...
    (comp.programming)