Scarborough has asked for the wisdom of the Perl Monks concerning the following question:
My problem is I have a data structure as follows
The hashes come from a number of XML files and there are about 70 hahses in the array.@job_data = ({'name'='job1', 'runs'='19:20'}, {'name'='job2', 'runs'='17:22'}, {'name'='job3', 'runs'='19:25'})
Update
With the advice from dws I used this sub to deal with my problem, I'm sure someone will come up with a simple one liner that does the same, but I'm just a hopeless sinner.
sub by_time{ my $a_time = $a->{'starts'}; my $b_time = $b->{'starts'}; my @aparts = split ':', $a_time; my @bparts = split ':', $b_time; #print $aparts[0]."\t".$bparts[0]."\n"; if ($aparts[0] > $bparts[0]){return 1} if ($aparts[0] < $bparts[0]){return 0} else { if ($aparts[1] > $bparts[1]){return 1} if ($aparts[1] < $bparts[1]){return 0} else{return 1} }; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Sorting an array of hashes
by dave_the_m (Monsignor) on Jul 28, 2004 at 08:42 UTC | |
by Scarborough (Hermit) on Jul 28, 2004 at 09:01 UTC | |
|
Re: Sorting an array of hashes
by dws (Chancellor) on Jul 28, 2004 at 08:47 UTC | |
by Scarborough (Hermit) on Jul 28, 2004 at 09:04 UTC | |
|
Re: Sorting an array of hashes
by davorg (Chancellor) on Jul 28, 2004 at 08:47 UTC | |
by Scarborough (Hermit) on Jul 28, 2004 at 08:58 UTC | |
|
Re: Sorting an array of hashes
by Anonymous Monk on Jul 28, 2004 at 20:26 UTC |