while (my $row = $sth->fetchrow_hashref) { $$patients{$row->{'pat_id'}} ||= { first_name => "$row->{'first_name'}", last_name => "$row->{'last_name'}", dme_num => "$row->{'dme_num'}", dme_pid => "$row->{'dme_pid'}", phone => "$row->{'phone'}", pid => "$row->{'pat_id'}" }; my $hash = { file_name => "$row->{'file_name'}", file_type => "$row->{'file_type'}", date_uploaded => "$row->{'date_uploaded'}", date_faxed => "$row->{'date_faxed'}" }; push(@{$$patients{$row->{'pat_id'}}->{files}}, $hash); if (($row->{'date_uploaded'} < $$patients{$row->{'pat_id'}}->{'o +ld_file'}) or (!$$patients{$row->{'pat_id'}}->{'old_file'})) { $$patients{$row->{'pat_id'}}->{'old_file'} = $row->{'date_upl +oaded'}; } $x++; }
ormy %sorted = sort { $patients->{$a}{old_file} cmp $patients->{$b}{old_file} } (keys %{$patients}); my $patients = \%sorted; # or put { } around the sort expression to do it one line.
And for some odd reason $patients is no longer a hash ref??sort { $$patients{$a}->{old_file} cmp $$patients{$b}->{old_file} }
In reply to Re^4: Sorting a Hash Ref
by bkiahg
in thread Sorting a Hash Ref
by bkiahg
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |