I have spent an afternooon trying to work this one out and it has me stumped, if anyone can surggest a resource which can do this I will be enturnally grateful.
My problem is I have a data structure as follows
@job_data = ({'name'='job1', 'runs'='19:20'},
{'name'='job2', 'runs'='17:22'},
{'name'='job3', 'runs'='19:25'})
The hashes come from a number of XML files and there are about 70 hahses in the array.
What I need to do is sort the hashes in to time order on the string representation of time in the 'runs' value.
Can anyone offer help. Thanks in advance.
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}
};
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.