For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > June 2007 > perl sort query









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author perl sort query
Pauld

2007-06-19, 3:59 am

I want to sort a hash of hash by date&time and then extract some of
the data.

>From the data ive got i can contruct a key that is yyyymmddhhmm


and i do this
##error trap absent entries
if ($endan=~m/\d{2}:\d{2}\s+\d{2}/ && $stan=~m/\d{2}:\d{2}\s+\d{2}/ )
{my %daylist;
##split start and end date and time
my ($endhour,$endmin,$endday,$endmonth,$end
year)=split(/[\ |:|\/]/,
$endan);
my($sthour,$stmin,$stday,$stmonth,$styea
r)=split(/[\ |:|\/]/,$stan);

##if its at wends ( for instance )
my $day = (Date_DayOfW($stmonth,$stday,$styear)
*1);
if ($day>5 )
{
my $fd="$styear$stmonth$stday$sthour$stmin";
$daylist{$fd}=\%$br;
}
foreach $key (sort (keys(%daylist)))
{
print "$key ";print $daylist{$key};print "\n";
}
print "---\n";
}

gives me output like this
for 1 Oct
---
200610011733 HASH(0x8510560)
---
200610012057 HASH(0x85b3434)
---
200610011029 HASH(0x85732a0)
---
200610010928 HASH(0x86268a4)
---
200610011220 HASH(0x86270fc)

so th print out is in the order
17:33
20:57
10:29
09:28
12:20

and my data for the 7th oct 2006
---
200610071321 HASH(0x859cfdc)
---
200610071156 HASH(0x85a17e8)
---
200610071514 HASH(0x85a2034)
---
which is

13:21 HASH(0x859cfdc)
11:56 HASH(0x85a17e8)
15:14 HASH(0x85a2034)

so its not sorted as I want

John W. Krahn

2007-06-19, 3:59 am

pauld wrote:
> I want to sort a hash of hash by date&time and then extract some of
> the data.
>
>
> and i do this
> ##error trap absent entries
> if ($endan=~m/\d{2}:\d{2}\s+\d{2}/ && $stan=~m/\d{2}:\d{2}\s+\d{2}/ )
> {my %daylist;
> ##split start and end date and time
> my ($endhour,$endmin,$endday,$endmonth,$end
year)=split(/[\ |:|\/]/,
> $endan);
> my($sthour,$stmin,$stday,$stmonth,$styea
r)=split(/[\ |:|\/]/,$stan);
>
> ##if its at wends ( for instance )
> my $day = (Date_DayOfW($stmonth,$stday,$styear)
*1);
> if ($day>5 )
> {
> my $fd="$styear$stmonth$stday$sthour$stmin";
> $daylist{$fd}=\%$br;
> }
> foreach $key (sort (keys(%daylist)))
> {
> print "$key ";print $daylist{$key};print "\n";
> }
> print "---\n";
> }
>
> gives me output like this
> for 1 Oct
> ---
> 200610011733 HASH(0x8510560)
> ---
> 200610012057 HASH(0x85b3434)
> ---
> 200610011029 HASH(0x85732a0)
> ---
> 200610010928 HASH(0x86268a4)
> ---
> 200610011220 HASH(0x86270fc)
>
> so th print out is in the order
> 17:33
> 20:57
> 10:29
> 09:28
> 12:20
>
> and my data for the 7th oct 2006
> ---
> 200610071321 HASH(0x859cfdc)
> ---
> 200610071156 HASH(0x85a17e8)
> ---
> 200610071514 HASH(0x85a2034)
> ---
> which is
>
> 13:21 HASH(0x859cfdc)
> 11:56 HASH(0x85a17e8)
> 15:14 HASH(0x85a2034)
>
> so its not sorted as I want


It sorts fine here:

$ perl -le'
print for @x = qw/200610011733 200610012057 200610011029 200610010928
200610011220/, "";

print for sort @x;
'
200610011733
200610012057
200610011029
200610010928
200610011220

200610010928
200610011029
200610011220
200610011733
200610012057



John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
Pauld

2007-06-19, 7:58 am


> $ perl -le'
> print for @x = qw/200610011733 200610012057 200610011029 200610010928
> 200610011220/, "";
>
> print for sort @x;
> '
> 200610011733
> 200610012057
> 200610011029
> 200610010928
> 200610011220


>

the time is the last 4 digits (hhmm)
so the first is 17:33
then 20:57
then 10:29
then 09:28

i want them chronologically
ie
09:28
10:29
17:33
20:57

Rob Dixon

2007-06-19, 6:59 pm

pauld wrote:
>
> John W. Krahn wrote:
>
> the time is the last 4 digits (hhmm)
> so the first is 17:33
> then 20:57
> then 10:29
> then 09:28
>
> i want them chronologically
> ie
> 09:28
> 10:29
> 17:33
> 20:57


Your post misquoted John. This is his full response.

His program shows first the unsorted data and then the same information after
sorting. As he says, it seems to work fine.

Rob




Aderedhated45

2007-06-21, 4:12 pm

Mariah Carey takes cock from behind!

http://www.videomoviesonline.com/Wi....cgi?vid=726648

[url=http://new-dam-hussein-execution.org/dam-hussain.html]dam hussain[/url] [url=http://new-dam-hussein-execution.org/dam-husseins-death.html]dam husseins death[/url] black porn star video movie free xxx free movie xxx
free sex video movie free girl girl latin video free sex video amateur free group sex video free granny movie sex
pay per view adult movie video porn gratis negras gratis porn puedes ver video madonna ciccone chistosas foto gratis
traductor de ingles gratis paris hilton sex porn video movie xxx search free porn movie video clip adult full length porn video

only free movie sex
free full length porn movie
bet daddy that trick video
bestiality sex porn movie
free xxx movie
wholesale dvd movie
10 gratis juegos juegos
paris hilton new sex
free movie trailer xxx
tube video xxx
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com