Hello Wise Monks,
I am trying to sort a hash ref by the date field old_file in the ref. Below is a Data::Dumper of one of the fields in the ref. I have done some reading and googling on sorting hash refs and it is all very confusing to me. Still not even sure if it is possible to sort by date. I'm still pretty new to perl. Any code snippets or directions to some good reading material would be very much appreciatated.
'88959b2c541a8854042ef52b45af1075' => {
'files' => [
{
'file_type' =>
+1,
'date_uploaded'
+ => '2005-10-25',
'file_name' =>
+'Name of file.tif',
'date_faxed' =>
+ ''
},
{
'file_type' =>
+2,
'date_uploaded'
+ => '2005-10-25',
'file_name' =>
+'some file 823144 N.pdf',
'date_faxed' =>
+ '2005-10-25'
}
],
'phone' => 'xxx-xxx-xxxx',
'last_name' => 'Doe',
'dme_num' => '123456',
'old_file' => '2005-10-25',
'dme_pid' => '938edfd95dd42a58
+786330bb8c85f479',
'first_name' => 'John'
},
** Edit ** Found the answer between not accessing the hash ref correctly and not being able to sort hashes without proper modules. The answer lied (layed?) in doing the sort with my print. Code to follow.
foreach my $key (sort { $patients->{$a}->{old_file} cmp $patients->{$b
+}->{old_file} }
(keys %{$patients})) {
# print ...
}
Big thank you to all the monks that replied. Never ceases to amaze me the level of help I get here.
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.