Re: sorting data - hash vs. list
- From: "Fred@xxxxxxxx" <Fred@xxxxxxxx>
- Date: Mon, 12 Sep 2005 18:19:13 -0500
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
.
- References:
- sorting data - hash vs. list
- From: Fred@xxxxxxxx
- Re: sorting data - hash vs. list
- From: Matt Garrish
- sorting data - hash vs. list
- Prev by Date: Install Perl 5.8.7 i386 for ImageMagick-perl-6.2.4-5.i386
- Next by Date: Re: sorting data - hash vs. list
- Previous by thread: Re: sorting data - hash vs. list
- Next by thread: Re: sorting data - hash vs. list
- Index(es):
Relevant Pages
|